Repository navigation
Expand file tree
/
Copy pathsuite_test.go
More file actions
182 lines (143 loc) · 3.68 KB
/
Copy pathsuite_test.go
File metadata and controls
182 lines (143 loc) · 3.68 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package got
import (
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
)
func TestTestSuite(t *testing.T) {
t.Run("single case", func(t *testing.T) {
ctrl := gomock.NewController(t)
mockT := NewMockT(ctrl)
mockT.EXPECT().Helper().AnyTimes()
var cases []TestCase
suite := TestSuite{
Dir: "testdata/suite/single-case",
TestFunc: func(t *testing.T, tc TestCase) {
cases = append(cases, tc)
type Test struct {
Input string `testdata:"input.txt"`
}
var test Test
tc.Load(mockT, &test)
require.EqualValues(t, "hello world", test.Input)
},
}
suite.Run(t)
require.ElementsMatch(t, []TestCase{
{
Name: "test-case-1",
Dir: "testdata/suite/single-case/test-case-1",
},
}, cases)
})
t.Run("multiple cases", func(t *testing.T) {
ctrl := gomock.NewController(t)
mockT := NewMockT(ctrl)
mockT.EXPECT().Helper().AnyTimes()
var cases []TestCase
suite := TestSuite{
Dir: "testdata/suite/multiple-cases",
TestFunc: func(t *testing.T, tc TestCase) {
cases = append(cases, tc)
type Test struct {
Input string `testdata:"input.txt"`
}
var test Test
tc.Load(mockT, &test)
require.EqualValues(t, "hello world", test.Input)
},
}
suite.Run(t)
require.ElementsMatch(t, []TestCase{
{
Name: "test-case-1",
Dir: "testdata/suite/multiple-cases/test-case-1",
},
{
Name: "test-case-2",
Dir: "testdata/suite/multiple-cases/test-case-2",
},
{
Name: "test-case-3",
Dir: "testdata/suite/multiple-cases/test-case-3",
},
}, cases)
})
t.Run("skip", func(t *testing.T) {
ctrl := gomock.NewController(t)
mockT := NewMockT(ctrl)
mockT.EXPECT().Helper().AnyTimes()
var cases []TestCase
suite := TestSuite{
Dir: "testdata/suite/skip",
TestFunc: func(t *testing.T, tc TestCase) {
cases = append(cases, tc)
type Test struct {
Input string `testdata:"input.txt"`
}
var test Test
tc.Load(mockT, &test)
require.EqualValues(t, "hello world", test.Input)
},
}
suite.Run(t)
require.ElementsMatch(t, []TestCase{
{
Name: "test-case-1",
Dir: "testdata/suite/skip/test-case-1",
},
{
Name: "test-case-3",
Dir: "testdata/suite/skip/test-case-3",
},
}, cases)
})
t.Run("shared dir", func(t *testing.T) {
ctrl := gomock.NewController(t)
mockT := NewMockT(ctrl)
mockT.EXPECT().Helper().AnyTimes()
var cases []TestCase
suite := TestSuite{
Dir: "testdata/suite/shared-dir/cases",
SharedDir: "testdata/suite/shared-dir/common",
TestFunc: func(t *testing.T, tc TestCase) {
cases = append(cases, tc)
type Test struct {
Input string `testdata:"input.txt"`
}
var test Test
tc.Load(mockT, &test)
switch tc.Name {
case "test-case-1":
require.EqualValues(t, "override", test.Input)
case "test-case-2":
require.EqualValues(t, "hello world", test.Input)
case "test-case-3":
require.EqualValues(t, "hello world", test.Input)
default:
t.Fatalf("unexpected test case %s", tc.Name)
}
},
}
suite.Run(t)
spew.Dump(cases)
require.ElementsMatch(t, []TestCase{
{
Name: "test-case-1",
Dir: "testdata/suite/shared-dir/cases/test-case-1",
SharedDir: "testdata/suite/shared-dir/common/test-case-1",
},
{
Name: "test-case-2",
Dir: "testdata/suite/shared-dir/cases/test-case-2",
SharedDir: "testdata/suite/shared-dir/common/test-case-2",
},
{
Name: "test-case-3",
Dir: "testdata/suite/shared-dir/cases/test-case-3",
SharedDir: "testdata/suite/shared-dir/common/test-case-3",
},
}, cases)
})
}