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
|
package middleware
import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestStackList(t *testing.T) {
s := NewStack("fooStack", func() interface{} { return struct{}{} })
s.Initialize.Add(mockInitializeMiddleware("first"), After)
s.Serialize.Add(mockSerializeMiddleware("second"), After)
s.Build.Add(mockBuildMiddleware("third"), After)
s.Finalize.Add(mockFinalizeMiddleware("fourth"), After)
s.Deserialize.Add(mockDeserializeMiddleware("fifth"), After)
actual := s.List()
expect := []string{
"fooStack",
(*InitializeStep)(nil).ID(),
"first",
(*SerializeStep)(nil).ID(),
"second",
(*BuildStep)(nil).ID(),
"third",
(*FinalizeStep)(nil).ID(),
"fourth",
(*DeserializeStep)(nil).ID(),
"fifth",
}
if diff := cmp.Diff(expect, actual); len(diff) != 0 {
t.Errorf("expect and actual stack list differ\n%s", diff)
}
}
func TestStackString(t *testing.T) {
s := NewStack("fooStack", func() interface{} { return struct{}{} })
s.Initialize.Add(mockInitializeMiddleware("first"), After)
s.Serialize.Add(mockSerializeMiddleware("second"), After)
s.Build.Add(mockBuildMiddleware("third"), After)
s.Finalize.Add(mockFinalizeMiddleware("fourth"), After)
s.Deserialize.Add(mockDeserializeMiddleware("fifth"), After)
actual := s.String()
expect := strings.Join([]string{
"fooStack",
"\t" + (*InitializeStep)(nil).ID(),
"\t\t" + "first",
"\t" + (*SerializeStep)(nil).ID(),
"\t\t" + "second",
"\t" + (*BuildStep)(nil).ID(),
"\t\t" + "third",
"\t" + (*FinalizeStep)(nil).ID(),
"\t\t" + "fourth",
"\t" + (*DeserializeStep)(nil).ID(),
"\t\t" + "fifth",
"",
}, "\n")
if diff := cmp.Diff(expect, actual); len(diff) != 0 {
t.Errorf("expect and actual stack list differ\n%s", diff)
}
}
|