generated from bradfordwagner/gh-template-go-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers_test.go
129 lines (112 loc) · 2.42 KB
/
matchers_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
package bwutil_test
import (
"github.com/bradfordwagner/go-util"
mock_bwutil "github.com/bradfordwagner/go-util/mocks/bwutil"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
)
var _ = Describe("Matchers", func() {
var ctrl *gomock.Controller
BeforeEach(func() { ctrl = gomock.NewController(GinkgoT()) })
Context("MatcherOneOf", func() {
type args struct {
set []int
invokeWith []int
}
type res struct {
}
var test = func(a args, r res) {
invoke := mock_bwutil.NewMockStubOneOf(ctrl)
matcher := bwutil.NewMatcherOneOf(a.set)
invoke.EXPECT().Invoke(matcher).Times(len(a.invokeWith))
for _, v := range a.invokeWith {
invoke.Invoke(v)
}
ctrl.Finish()
}
It("invokes with everything expected", func() {
test(args{
set: []int{1, 2, 3},
invokeWith: []int{1, 2, 3},
}, res{})
})
It("invokes only some of the set", func() {
test(args{
set: []int{1, 2, 3},
invokeWith: []int{1, 3},
}, res{})
})
})
Context("MatcherConversionOneOf", func() {
type orig struct {
i int
}
type args struct {
set []int
invokeWith []orig
}
type res struct {
}
var test = func(a args, r res) {
invoke := mock_bwutil.NewMockStubConversionOneOf(ctrl)
matcher := bwutil.NewMatcherConversionOneOf(a.set, func(o orig) int {
return o.i
})
invoke.EXPECT().Invoke(matcher).Times(len(a.invokeWith))
for _, v := range a.invokeWith {
invoke.Invoke(v)
}
ctrl.Finish()
}
It("", func() {
test(args{
set: []int{1, 2},
invokeWith: []orig{
{i: 1},
{i: 2},
},
}, res{})
})
})
It("NewMatcherConversionExploderOneOf", func() {
type value struct {
arr []int
}
type args struct {
values []value
set []int
}
var test = func(a args) {
invoke := mock_bwutil.NewMockStubConversionOneOf(ctrl)
matcher := bwutil.NewMatcherConversionExploderOneOf(a.set, func(v value) []int {
return v.arr
})
invoke.EXPECT().Invoke(matcher).Times(len(a.values))
for _, v := range a.values {
invoke.Invoke(v)
}
ctrl.Finish()
}
// run tests
test(args{
values: []value{
{arr: []int{1, 2}},
},
set: []int{1, 2},
})
test(args{
values: []value{
{arr: []int{1, 2}},
{arr: []int{2, 1}},
},
set: []int{1, 2},
})
test(args{
values: []value{
{arr: []int{1, 2}},
{arr: []int{3, 4}},
},
set: []int{1, 2, 3, 4},
})
})
})