3838 Environment = types.Environment
3939 Func = types.EnvFunc
4040 FeatureFunc = types.FeatureEnvFunc
41-
42- actionRole uint8
4341)
4442
4543type testEnv struct {
@@ -187,7 +185,7 @@ func (e *testEnv) processTestActions(t *testing.T, actions []action) {
187185 var err error
188186 for _ , action := range actions {
189187 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 )
191189 }
192190 }
193191}
@@ -196,25 +194,23 @@ func (e *testEnv) processTestActions(t *testing.T, actions []action) {
196194// workflow of orchestrating the feature execution be running the action configured by BeforeEachFeature /
197195// AfterEachFeature.
198196func (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 ())
210199
211200 // execute feature test
212201 e .ctx = e .execFeature (e .ctx , t , featureName , feature )
213202
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 {
216212 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 )
218214 }
219215 }
220216}
@@ -327,7 +323,6 @@ func (e *testEnv) Finish(funcs ...Func) types.Environment {
327323// package. This method will all Env.Setup operations prior to
328324// starting the tests and run all Env.Finish operations after
329325// before completing the suite.
330- //
331326func (e * testEnv ) Run (m * testing.M ) int {
332327 if e .ctx == nil {
333328 panic ("context not set" ) // something is terribly wrong.
@@ -354,15 +349,15 @@ func (e *testEnv) Run(m *testing.M) int {
354349 for _ , fin := range finishes {
355350 // context passed down to each finish step
356351 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 )
358353 }
359354 }
360355 }()
361356
362357 for _ , setup := range setups {
363358 // context passed down to each setup
364359 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 )
366361 }
367362 }
368363
0 commit comments