-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_test.go
78 lines (67 loc) · 1.61 KB
/
job_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main_test
import (
"io/ioutil"
"log"
"os"
"path"
"testing"
crudeci "github.com/mlloreda/crudeci"
)
func TestCloneRepo(t *testing.T) {
t.Parallel()
cases := []struct {
name string
repo string
tmpDir string
tmpDirPattern string
checkFor string
expError bool
}{
{
name: "success case",
tmpDirPattern: "test",
repo: "https://github.com/mlloreda/dotfiles",
checkFor: "dot_vimrc",
expError: false,
},
{
name: "failure case",
tmpDirPattern: "test",
repo: "https://github.com/mlloreda/dotfiles",
checkFor: "invalid_file",
expError: true,
},
// Disabling. Git protocol urls will only succeed locally with
// appropriate private key.
// {
// name: "failure case (git)",
// tmpDirPattern: "test",
// repo: "[email protected]:mlloreda/invalid",
// expError: true,
// },
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
wd := testCreateTempDir(t, tc.tmpDir, tc.tmpDirPattern)
targetDir := path.Join(wd, path.Base(tc.repo))
err := crudeci.CloneRepo(tc.repo, targetDir)
if err != nil {
t.Fatalf("error: %v", err)
}
_, err = crudeci.Exists(path.Join(targetDir, tc.checkFor))
if (tc.expError == false && err != nil) ||
(tc.expError == true && err == nil) {
t.Fatalf("error: %v", err)
}
})
}
}
func testCreateTempDir(t *testing.T, dir, pattern string) string {
t.Helper()
wd, err := ioutil.TempDir(dir, pattern)
if err != nil {
log.Fatalf("%s", err)
}
defer os.RemoveAll(wd)
return wd
}