-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan_test.go
113 lines (99 loc) · 2.17 KB
/
plan_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
package sagas
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_plan_add(t *testing.T) {
t.Parallel()
action := NewAction(func(ctx context.Context) error { return nil })
type args struct {
identifier Identifier
event Event
}
tests := []struct {
name string
args args
want planMap
}{
{
name: "[SUCCESS] Should add an action to the plan",
args: args{
identifier: identifier("identifier"),
event: Completed,
},
want: planMap{
identifier("identifier"): {
Completed: []Action{action},
},
},
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
assert.NotPanics(t, func() {
p := newPlan()
p.add(test.args.identifier, test.args.event, action)
got := p
assert.Equal(t, test.want, got)
})
})
}
}
func Test_plan_get(t *testing.T) {
t.Parallel()
action := NewAction(func(ctx context.Context) error { return nil })
p := newPlan()
p.add(identifier("identifier"), Completed, action)
type args struct {
identifier Identifier
event Event
}
tests := []struct {
name string
args args
wantActions []Action
wantOk bool
}{
{
name: "[SUCCESS] Should return a list of actions and true",
args: args{
identifier: identifier("identifier"),
event: Completed,
},
wantActions: []Action{action},
wantOk: true,
},
{
name: "[SUCCESS] Should return a nil list of actions and false - identifier does not exist",
args: args{
identifier: identifier("not-exists"),
event: Completed,
},
wantActions: nil,
wantOk: false,
},
{
name: "[SUCCESS] Should return a nil list of actions and false - event does not exist",
args: args{
identifier: identifier("identifier"),
event: Successed,
},
wantActions: nil,
wantOk: false,
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
assert.NotPanics(t, func() {
got, ok := p.get(test.args.identifier, test.args.event)
assert.Equal(t, test.wantActions, got)
assert.Equal(t, test.wantOk, ok)
})
})
}
}