package f2 import ( "fmt" "testing" ) // TODO: tests type action struct { phase Phase // only one set of functions is actually set/used for an action, based // on the Phase fns []FrameworkFn featureFns []FeatureFn testFns []FrameworkTestFn } // runWithTest executes the test functions for this action func (a action) runWithT(ctx Context, t *testing.T) (Context, error) { switch a.phase { case phaseBeforeTest, phaseAfterTest: for _, f := range a.testFns { var err error ctx, err = f(ctx, t) if err != nil { return ctx, err } } default: return ctx, fmt.Errorf("action called for %s, expected [%s, %s]", a.phase, phaseBeforeTest, phaseAfterTest) } return ctx, nil } // runWithFeature executes the feature functions for this action func (a action) runWithFeature(ctx Context, t *testing.T, feat Feature) (Context, error) { switch a.phase { case phaseBeforeFeature, phaseAfterFeature: for _, f := range a.featureFns { var err error ctx, err = f(ctx, t, feat) if err != nil { return ctx, err } } default: return ctx, fmt.Errorf("action called for %s, expected [%s, %s]", a.phase, phaseBeforeFeature, phaseAfterFeature) } return ctx, nil } // run executes the framework functions for this action func (a action) run(ctx Context) (Context, error) { for _, f := range a.fns { var err error ctx, err = f(ctx) if err != nil { return ctx, err } } return ctx, nil }