-
Notifications
You must be signed in to change notification settings - Fork 8
/
registry_test.go
121 lines (114 loc) · 3.56 KB
/
registry_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package polaris
import (
"testing"
mapset "github.com/deckarep/golang-set/v2"
)
func TestRegisterWorkflow(t *testing.T) {
type args struct {
workflowKey string
workflow IWorkflow
}
tests := []struct {
name string
args args
wantErr bool
skipHierarchyCheck bool
wantHierarchy [][]BuilderMeta
}{
{
name: "Base_Successful_Test",
args: args{
workflowKey: "testWorkflow",
workflow: testWorkflow{},
},
wantErr: false,
wantHierarchy: [][]BuilderMeta{
{
{
Name: Name(alphaBuilder{}),
Consumes: mapset.NewSet[string](Name(alphaConsumes{})),
Produces: Name(alphaProduces{}),
Optionals: mapset.NewSet[string](),
Accesses: mapset.NewSet[string](),
},
},
{
{
Name: Name(betaBuilder{}),
Consumes: mapset.NewSet[string](Name(alphaProduces{})),
Produces: Name(betaProduces{}),
Optionals: mapset.NewSet[string](),
Accesses: mapset.NewSet[string](),
},
},
{
{
Name: Name(terminator{}),
Consumes: mapset.NewSet[string](Name(alphaProduces{}), Name(betaProduces{})),
Produces: Name(workflowTerminated{}),
Optionals: mapset.NewSet[string](),
Accesses: mapset.NewSet[string](),
},
},
},
},
{
name: "Redundant_Builder_Failure_Test",
args: args{
workflowKey: "redundantBuilderWorkflow",
workflow: redundantBuilderFailureWorklow{},
},
wantErr: true,
skipHierarchyCheck: true,
},
{
name: "Empty_Target_Data_Failure_Test",
args: args{
workflowKey: "emptyTargetDataWorkflow",
workflow: emptyTargetDataWorkflow{},
},
wantErr: true,
skipHierarchyCheck: true,
},
}
mockStorage := &mockStorage{
store: make(map[string]interface{}),
}
InitRegistry(mockStorage)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := RegisterWorkflow(tt.args.workflowKey, tt.args.workflow); (err != nil) != tt.wantErr {
t.Errorf("RegisterWorkflow() error = %v, wantErr %v", err, tt.wantErr)
}
if tt.skipHierarchyCheck {
return
}
dataFlowInterface, _ := mockStorage.Read(tt.args.workflowKey)
dataFlow := dataFlowInterface.(DataFlow)
gotHierarchy := dataFlow.DependencyHierarchy
wantHierarchy := tt.wantHierarchy
compareHierarchies(wantHierarchy, gotHierarchy, t)
})
}
}
func compareHierarchies(wantHierarchy [][]BuilderMeta, gotHierarchy [][]BuilderMeta, t *testing.T) {
for level := range gotHierarchy {
for index, builder := range gotHierarchy[level] {
if wantHierarchy[level][index].Name != builder.Name {
t.Errorf("Builder Name %s does not match %s at %d %d", wantHierarchy[level][index].Name, builder.Name, level, index)
}
if !wantHierarchy[level][index].Consumes.Equal(builder.Consumes) {
t.Errorf("Builder Consumes %s does not match %s at %d %d", wantHierarchy[level][index].Consumes, builder.Consumes, level, index)
}
if !wantHierarchy[level][index].Accesses.Equal(builder.Accesses) {
t.Errorf("Builder Accesses %s does not match %s at %d %d", wantHierarchy[level][index].Accesses, builder.Accesses, level, index)
}
if !wantHierarchy[level][index].Optionals.Equal(builder.Optionals) {
t.Errorf("Builder Optionals %s does not match %s at %d %d", wantHierarchy[level][index].Optionals, builder.Optionals, level, index)
}
if wantHierarchy[level][index].Produces != builder.Produces {
t.Errorf("Builder Produces %s does not match %s at %d %d", wantHierarchy[level][index].Produces, builder.Produces, level, index)
}
}
}
}