-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoteto_workflow_test.go
103 lines (96 loc) · 2.01 KB
/
poteto_workflow_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package poteto
import (
"errors"
"testing"
)
func TestNewPotetoWorkflows(t *testing.T) {
pw := NewPotetoWorkflows()
if pw == nil {
t.Errorf("Expected: not nil, Got: nil")
}
}
func TestRegisterWorkflow(t *testing.T) {
tests := []struct {
name string
workflowTypes []string
priorities []uint
expecteds []uint
}{
{
"Test append workflow",
[]string{"startUp"},
[]uint{1},
[]uint{1},
},
{
"Test append workflow with priority",
[]string{"startUp", "startUp"},
[]uint{2, 1},
[]uint{1, 2},
},
{
"Test just append expected workflow",
[]string{"unexpected", "startUp", "startUp"},
[]uint{1, 2, 1},
[]uint{1, 2},
},
}
for _, it := range tests {
t.Run(it.name, func(t *testing.T) {
pw := &potetoWorkflows{}
for i := range it.priorities {
pw.RegisterWorkflow(it.workflowTypes[i], it.priorities[i], nil)
}
for i := range pw.startUpWorkflows {
if pw.startUpWorkflows[i].priority != it.expecteds[i] {
t.Errorf("Expected: %d, Got: %d", it.expecteds[i], pw.startUpWorkflows[i].priority)
}
}
})
}
}
func TestApplyStartUpWorkflows(t *testing.T) {
tests := []struct {
name string
workflows []UnitWorkflow
hasError bool
}{
{
"Test apply start up workflows",
[]UnitWorkflow{
{1, func() error { return nil }},
{2, func() error { return nil }},
},
false,
},
{
"Test apply start up workflows with error",
[]UnitWorkflow{
{1, func() error { return errors.New("error") }},
{2, func() error { return nil }},
{3, func() error { return nil }},
},
true,
},
{
"Test apply start up workflows with no workflows",
[]UnitWorkflow{},
false,
},
}
for _, it := range tests {
t.Run(it.name, func(t *testing.T) {
pw := &potetoWorkflows{startUpWorkflows: it.workflows}
err := pw.ApplyStartUpWorkflows()
if it.hasError {
if err == nil {
t.Errorf("should throw an error")
}
} else {
if err != nil {
t.Errorf("should not throw an error")
}
}
})
}
}