-
Notifications
You must be signed in to change notification settings - Fork 2
/
perm_test.go
78 lines (65 loc) · 1.76 KB
/
perm_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
package perm_test
import (
"strings"
"testing"
"github.com/golang/mock/gomock"
"github.com/tkrop/go-testing/mock"
"github.com/tkrop/go-testing/perm"
"github.com/tkrop/go-testing/test"
)
//go:generate mockgen -package=perm_test -destination=mock_iface_test.go -source=perm_test.go IFace
type IFace interface {
CallA(string)
}
func CallA(input string) mock.SetupFunc {
return func(mocks *mock.Mocks) any {
return mock.Get(mocks, NewMockIFace).EXPECT().
CallA(input).Do(mocks.Do(IFace.CallA))
}
}
func SetupPermTestABCDEF(mocks *mock.Mocks) *perm.Test {
iface := mock.Get(mocks, NewMockIFace)
return perm.NewTest(mocks,
perm.TestMap{
"a": func(test.Test) { iface.CallA("a") },
"b": func(test.Test) { iface.CallA("b") },
"c": func(test.Test) { iface.CallA("c") },
"d": func(test.Test) { iface.CallA("d") },
"e": func(test.Test) { iface.CallA("e") },
"f": func(test.Test) { iface.CallA("f") },
})
}
func MockSetup(t gomock.TestReporter, mockSetup mock.SetupFunc) *mock.Mocks {
return mock.NewMocks(t).Expect(mockSetup)
}
var testPermTestParams = perm.ExpectMap{
"b-a-c-d-e-f": test.Success,
"a-b-c-d-e-f": test.Success,
"a-c-b-d-e-f": test.Success,
"a-c-d-b-e-f": test.Success,
"a-c-d-e-b-f": test.Success,
"a-c-d-e-f-b": test.Success,
}
func TestPermTest(t *testing.T) {
test.Map(t, testPermTestParams.Remain(test.Failure)).
Run(func(t test.Test, expect test.Expect) {
// Given
name := strings.Split(t.Name(), "/")[1]
perm := strings.Split(name, "-")
mockSetup := mock.Chain(
CallA("a"),
mock.Setup(
CallA("b"),
),
CallA("c"),
CallA("d"),
CallA("e"),
CallA("f"),
)
mock := MockSetup(t, mockSetup)
// When
test := SetupPermTestABCDEF(mock)
// Then
test.Test(t, perm, expect)
})
}