This repository was archived by the owner on Jun 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathworkflow_test.go
More file actions
83 lines (72 loc) · 1.3 KB
/
workflow_test.go
File metadata and controls
83 lines (72 loc) · 1.3 KB
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
79
80
81
82
83
package workflow_test
import (
"testing"
"github.com/coreos/go-workflow"
)
func TestBasicWorkflow(t *testing.T) {
var testVar bool
step := &workflow.Step{
Label: "modify testVar",
Run: func(c workflow.Context) error {
testVar = true
return nil
},
}
w := workflow.New()
w.Start = step
err := w.Run()
if err != nil {
t.Error(err)
}
if testVar != true {
t.Fail()
}
}
func TestDependancyWorkflow(t *testing.T) {
var testVars [4]bool
one := &workflow.Step{
Label: "modify testVar 1",
Run: func(c workflow.Context) error {
testVars[1] = true
return nil
},
}
three := &workflow.Step{
Label: "modify testVar 3",
Run: func(c workflow.Context) error {
testVars[3] = true
return nil
},
}
two := &workflow.Step{
Label: "modify testVar 2",
DependsOn: []*workflow.Step{three},
Run: func(c workflow.Context) error {
if !testVars[3] {
t.Fail()
}
testVars[2] = true
return nil
},
}
base := &workflow.Step{
Label: "modify testVar 0",
DependsOn: []*workflow.Step{one, two},
Run: func(c workflow.Context) error {
if !testVars[1] || !testVars[2] {
t.Fail()
}
testVars[0] = true
return nil
},
}
w := workflow.New()
w.Start = base
err := w.Run()
if err != nil {
t.Error(err)
}
if testVars[0] != true {
t.Fail()
}
}