38
38
Environment = types.Environment
39
39
Func = types.EnvFunc
40
40
FeatureFunc = types.FeatureEnvFunc
41
-
42
- actionRole uint8
43
41
)
44
42
45
43
type testEnv struct {
@@ -187,7 +185,7 @@ func (e *testEnv) processTestActions(t *testing.T, actions []action) {
187
185
var err error
188
186
for _ , action := range actions {
189
187
if e .ctx , err = action .runWithT (e .ctx , e .cfg , t ); err != nil {
190
- t .Fatalf ("BeforeEachTest failure: %s" , err )
188
+ t .Fatalf ("%s failure: %s" , action . role , err )
191
189
}
192
190
}
193
191
}
@@ -196,25 +194,23 @@ func (e *testEnv) processTestActions(t *testing.T, actions []action) {
196
194
// workflow of orchestrating the feature execution be running the action configured by BeforeEachFeature /
197
195
// AfterEachFeature.
198
196
func (e * testEnv ) processTestFeature (t * testing.T , featureName string , feature types.Feature ) {
199
- var err error
200
-
201
- // execute each feature
202
- beforeFeatureActions := e .getBeforeFeatureActions ()
203
- afterFeatureActions := e .getAfterFeatureActions ()
204
-
205
- for _ , action := range beforeFeatureActions {
206
- if e .ctx , err = action .runWithFeature (e .ctx , e .cfg , t , deepCopyFeature (feature )); err != nil {
207
- t .Fatalf ("BeforeEachTest failure: %s" , err )
208
- }
209
- }
197
+ // execute beforeEachFeature actions
198
+ e .processFeatureActions (t , feature , e .getBeforeFeatureActions ())
210
199
211
200
// execute feature test
212
201
e .ctx = e .execFeature (e .ctx , t , featureName , feature )
213
202
214
- // execute beforeFeature actions
215
- for _ , action := range afterFeatureActions {
203
+ // execute afterEachFeature actions
204
+ e .processFeatureActions (t , feature , e .getAfterFeatureActions ())
205
+ }
206
+
207
+ // processFeatureActions is used to run a series of feature action that were configured as
208
+ // BeforeEachFeature or AfterEachFeature
209
+ func (e * testEnv ) processFeatureActions (t * testing.T , feature types.Feature , actions []action ) {
210
+ var err error
211
+ for _ , action := range actions {
216
212
if e .ctx , err = action .runWithFeature (e .ctx , e .cfg , t , deepCopyFeature (feature )); err != nil {
217
- t .Fatalf ("BeforeEachTest failure: %s" , err )
213
+ t .Fatalf ("%s failure: %s" , action . role , err )
218
214
}
219
215
}
220
216
}
@@ -327,7 +323,6 @@ func (e *testEnv) Finish(funcs ...Func) types.Environment {
327
323
// package. This method will all Env.Setup operations prior to
328
324
// starting the tests and run all Env.Finish operations after
329
325
// before completing the suite.
330
- //
331
326
func (e * testEnv ) Run (m * testing.M ) int {
332
327
if e .ctx == nil {
333
328
panic ("context not set" ) // something is terribly wrong.
@@ -354,15 +349,15 @@ func (e *testEnv) Run(m *testing.M) int {
354
349
for _ , fin := range finishes {
355
350
// context passed down to each finish step
356
351
if e .ctx , err = fin .run (e .ctx , e .cfg ); err != nil {
357
- klog .V (2 ).ErrorS (err , "Finish action handlers" )
352
+ klog .V (2 ).ErrorS (err , "Cleanup failed" , "action" , fin . role )
358
353
}
359
354
}
360
355
}()
361
356
362
357
for _ , setup := range setups {
363
358
// context passed down to each setup
364
359
if e .ctx , err = setup .run (e .ctx , e .cfg ); err != nil {
365
- klog .Fatal ( err )
360
+ klog .Fatalf ( "%s failure: %s" , setup . role , err )
366
361
}
367
362
}
368
363
0 commit comments