@@ -18,7 +18,7 @@ type panickingExecutionStrategy struct{}
18
18
19
19
var _ harness.ExecutionStrategy = panickingExecutionStrategy {}
20
20
21
- func (panickingExecutionStrategy ) Execute (_ context.Context , _ []* harness.TestRun ) error {
21
+ func (panickingExecutionStrategy ) Run (_ context.Context , _ []harness.TestFn ) ([] error , error ) {
22
22
panic (testPanicMessage )
23
23
}
24
24
@@ -28,8 +28,8 @@ type erroringExecutionStrategy struct {
28
28
29
29
var _ harness.ExecutionStrategy = erroringExecutionStrategy {}
30
30
31
- func (e erroringExecutionStrategy ) Execute (_ context.Context , _ []* harness.TestRun ) error {
32
- return e .err
31
+ func (e erroringExecutionStrategy ) Run (_ context.Context , _ []harness.TestFn ) ([] error , error ) {
32
+ return [] error {}, e .err
33
33
}
34
34
35
35
func Test_TestHarness (t * testing.T ) {
@@ -40,7 +40,7 @@ func Test_TestHarness(t *testing.T) {
40
40
41
41
expectedErr := xerrors .New ("expected error" )
42
42
43
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
43
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
44
44
r1 := h .AddRun ("test" , "1" , fakeTestFns (nil , nil ))
45
45
r2 := h .AddRun ("test" , "2" , fakeTestFns (expectedErr , nil ))
46
46
@@ -65,7 +65,7 @@ func Test_TestHarness(t *testing.T) {
65
65
66
66
expectedErr := xerrors .New ("expected error" )
67
67
68
- h := harness .NewTestHarness (erroringExecutionStrategy {err : expectedErr })
68
+ h := harness .NewTestHarness (erroringExecutionStrategy {err : expectedErr }, harness. LinearExecutionStrategy {} )
69
69
_ = h .AddRun ("test" , "1" , fakeTestFns (nil , nil ))
70
70
71
71
err := h .Run (context .Background ())
@@ -76,7 +76,7 @@ func Test_TestHarness(t *testing.T) {
76
76
t .Run ("CatchesExecutionPanic" , func (t * testing.T ) {
77
77
t .Parallel ()
78
78
79
- h := harness .NewTestHarness (panickingExecutionStrategy {})
79
+ h := harness .NewTestHarness (panickingExecutionStrategy {}, harness. LinearExecutionStrategy {} )
80
80
_ = h .AddRun ("test" , "1" , fakeTestFns (nil , nil ))
81
81
82
82
err := h .Run (context .Background ())
@@ -93,7 +93,7 @@ func Test_TestHarness(t *testing.T) {
93
93
94
94
expectedErr := xerrors .New ("expected error" )
95
95
96
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
96
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
97
97
_ = h .AddRun ("test" , "1" , fakeTestFns (nil , expectedErr ))
98
98
99
99
err := h .Run (context .Background ())
@@ -107,7 +107,7 @@ func Test_TestHarness(t *testing.T) {
107
107
t .Run ("Panic" , func (t * testing.T ) {
108
108
t .Parallel ()
109
109
110
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
110
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
111
111
_ = h .AddRun ("test" , "1" , testFns {
112
112
RunFn : func (_ context.Context , _ string , _ io.Writer ) error {
113
113
return nil
@@ -125,6 +125,44 @@ func Test_TestHarness(t *testing.T) {
125
125
require .ErrorContains (t , err , "panic" )
126
126
require .ErrorContains (t , err , testPanicMessage )
127
127
})
128
+
129
+ t .Run ("CatchesExecutionError" , func (t * testing.T ) {
130
+ t .Parallel ()
131
+
132
+ expectedErr := xerrors .New ("expected error" )
133
+
134
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, erroringExecutionStrategy {err : expectedErr })
135
+ _ = h .AddRun ("test" , "1" , fakeTestFns (nil , nil ))
136
+
137
+ err := h .Run (context .Background ())
138
+ require .NoError (t , err )
139
+
140
+ err = h .Cleanup (context .Background ())
141
+ require .Error (t , err )
142
+ require .ErrorIs (t , err , expectedErr )
143
+ })
144
+
145
+ t .Run ("CatchesExecutionPanic" , func (t * testing.T ) {
146
+ t .Parallel ()
147
+
148
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, panickingExecutionStrategy {})
149
+ _ = h .AddRun ("test" , "1" , testFns {
150
+ RunFn : func (_ context.Context , _ string , _ io.Writer ) error {
151
+ return nil
152
+ },
153
+ CleanupFn : func (_ context.Context , _ string ) error {
154
+ return nil
155
+ },
156
+ })
157
+
158
+ err := h .Run (context .Background ())
159
+ require .NoError (t , err )
160
+
161
+ err = h .Cleanup (context .Background ())
162
+ require .Error (t , err )
163
+ require .ErrorContains (t , err , "panic" )
164
+ require .ErrorContains (t , err , testPanicMessage )
165
+ })
128
166
})
129
167
130
168
t .Run ("Panics" , func (t * testing.T ) {
@@ -133,7 +171,7 @@ func Test_TestHarness(t *testing.T) {
133
171
t .Run ("RegisterAfterStart" , func (t * testing.T ) {
134
172
t .Parallel ()
135
173
136
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
174
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
137
175
_ = h .Run (context .Background ())
138
176
139
177
require .Panics (t , func () {
@@ -144,7 +182,7 @@ func Test_TestHarness(t *testing.T) {
144
182
t .Run ("DuplicateTestID" , func (t * testing.T ) {
145
183
t .Parallel ()
146
184
147
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
185
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
148
186
149
187
name , id := "test" , "1"
150
188
_ = h .AddRun (name , id , fakeTestFns (nil , nil ))
@@ -157,7 +195,7 @@ func Test_TestHarness(t *testing.T) {
157
195
t .Run ("StartedTwice" , func (t * testing.T ) {
158
196
t .Parallel ()
159
197
160
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
198
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
161
199
h .Run (context .Background ())
162
200
163
201
require .Panics (t , func () {
@@ -168,7 +206,7 @@ func Test_TestHarness(t *testing.T) {
168
206
t .Run ("ResultsBeforeStart" , func (t * testing.T ) {
169
207
t .Parallel ()
170
208
171
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
209
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
172
210
173
211
require .Panics (t , func () {
174
212
h .Results ()
@@ -183,7 +221,7 @@ func Test_TestHarness(t *testing.T) {
183
221
endRun = make (chan struct {})
184
222
testsEnded = make (chan struct {})
185
223
)
186
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
224
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
187
225
_ = h .AddRun ("test" , "1" , testFns {
188
226
RunFn : func (_ context.Context , _ string , _ io.Writer ) error {
189
227
close (started )
@@ -210,22 +248,22 @@ func Test_TestHarness(t *testing.T) {
210
248
t .Run ("CleanupBeforeStart" , func (t * testing.T ) {
211
249
t .Parallel ()
212
250
213
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
251
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
214
252
215
253
require .Panics (t , func () {
216
254
h .Cleanup (context .Background ())
217
255
})
218
256
})
219
257
220
- t .Run ("ClenaupBeforeFinish " , func (t * testing.T ) {
258
+ t .Run ("CleanupBeforeFinish " , func (t * testing.T ) {
221
259
t .Parallel ()
222
260
223
261
var (
224
262
started = make (chan struct {})
225
263
endRun = make (chan struct {})
226
264
testsEnded = make (chan struct {})
227
265
)
228
- h := harness .NewTestHarness (harness.LinearExecutionStrategy {})
266
+ h := harness .NewTestHarness (harness.LinearExecutionStrategy {}, harness. LinearExecutionStrategy {} )
229
267
_ = h .AddRun ("test" , "1" , testFns {
230
268
RunFn : func (_ context.Context , _ string , _ io.Writer ) error {
231
269
close (started )
0 commit comments