-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline_test.go
74 lines (66 loc) · 1.56 KB
/
pipeline_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
package main_test
import (
"strings"
"testing"
crudeci "github.com/mlloreda/crudeci"
)
func TestBuildPipeline(t *testing.T) {
cases := []struct {
name string
build string
test string
expLen int
expSuccess bool
// steps map[string]string
}{
{
name: "success case",
build: "pwd",
test: "ls -lah",
expLen: 2,
expSuccess: true,
// steps: map[string]string{"build": "pwd", "test": "ls -lah"},
},
{
name: "failure case (# of steps mismatch)",
build: "pwd",
expLen: 2,
expSuccess: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
j := testCreateJob(t, tc.build, tc.test)
pipeline, err := crudeci.BuildPipeline(j)
if err != nil {
t.Fatalf("%v", err)
}
if tc.expLen != len(pipeline.Steps) && tc.expSuccess == true {
t.Fatalf("expected len %d, got len %d", tc.expLen, len(pipeline.Steps))
}
for _, step := range pipeline.Steps {
s := step.(*crudeci.Step)
cmd := strings.TrimSpace(s.Bin + " " + strings.Join(s.Args, " "))
if s.Name == "build" {
if cmd != tc.build {
t.Fatalf("expected %s, got %s", tc.build, cmd)
}
} else if s.Name == "test" {
if cmd != tc.test {
t.Fatalf("expected %s, got %s", tc.test, cmd)
}
}
}
})
}
}
func testCreateJob(t *testing.T, build, test string) *crudeci.Job {
t.Helper()
return &crudeci.Job{
Name: "testJob",
Repo: "https://github.com/mlloreda/dotfiles",
WorkingDir: ".",
Build: build,
Test: test,
}
}