-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
step_test.go
130 lines (103 loc) · 2.06 KB
/
step_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
122
123
124
125
126
127
128
129
130
package genny
import (
"context"
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
func Test_NewStep(t *testing.T) {
r := require.New(t)
_, err := NewStep(nil, 0)
r.Error(err)
s, err := NewStep(New(), 0)
r.NoError(err)
r.NotZero(s)
}
func Test_StepBefore(t *testing.T) {
r := require.New(t)
var actual []string
g := New()
g.RunFn(func(r *Runner) error {
actual = append(actual, "as")
return nil
})
s, err := NewStep(g, 0)
r.NoError(err)
b := New()
b.RunFn(func(r *Runner) error {
actual = append(actual, "before")
return nil
})
s.Before(b)
run := DryRunner(context.Background())
r.NoError(s.Run(run))
r.Equal([]string{"before", "as"}, actual)
}
func Test_StepBefore_Delete(t *testing.T) {
n := 5
for i := 0; i < n; i++ {
t.Run("deleting index "+strconv.Itoa(i), func(st *testing.T) {
r := require.New(st)
s, err := NewStep(New(), 0)
r.NoError(err)
var name string
for x := 0; x < n; x++ {
g := New()
del := s.Before(g)
if x == i {
name = g.StepName
del()
}
}
r.Len(s.before, n-1)
r.NotZero(name)
for _, g := range s.before {
r.NotEqual(name, g.StepName)
}
})
}
}
func Test_StepAfter(t *testing.T) {
r := require.New(t)
var actual []string
g := New()
g.RunFn(func(r *Runner) error {
actual = append(actual, "as")
return nil
})
s, err := NewStep(g, 0)
r.NoError(err)
b := New()
b.RunFn(func(r *Runner) error {
actual = append(actual, "after")
return nil
})
s.After(b)
run := DryRunner(context.Background())
r.NoError(s.Run(run))
r.Equal([]string{"as", "after"}, actual)
}
func Test_StepAfter_Delete(t *testing.T) {
n := 5
for i := 0; i < n; i++ {
t.Run("deleting index "+strconv.Itoa(i), func(st *testing.T) {
r := require.New(st)
s, err := NewStep(New(), 0)
r.NoError(err)
var name string
for x := 0; x < n; x++ {
g := New()
del := s.After(g)
if x == i {
name = g.StepName
del()
}
}
r.Len(s.after, n-1)
r.NotZero(name)
for _, g := range s.after {
r.NotEqual(name, g.StepName)
}
})
}
}