...

Source file src/edge-infra.dev/test/f2/action.go

Documentation: edge-infra.dev/test/f2

     1  package f2
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  // TODO: tests
     9  
    10  type action struct {
    11  	phase Phase
    12  
    13  	// only one set of functions is actually set/used for an action, based
    14  	// on the Phase
    15  	fns        []FrameworkFn
    16  	featureFns []FeatureFn
    17  	testFns    []FrameworkTestFn
    18  }
    19  
    20  // runWithTest executes the test functions for this action
    21  func (a action) runWithT(ctx Context, t *testing.T) (Context, error) {
    22  	switch a.phase {
    23  	case phaseBeforeTest, phaseAfterTest:
    24  		for _, f := range a.testFns {
    25  			var err error
    26  			ctx, err = f(ctx, t)
    27  			if err != nil {
    28  				return ctx, err
    29  			}
    30  		}
    31  	default:
    32  		return ctx, fmt.Errorf("action called for %s, expected [%s, %s]",
    33  			a.phase, phaseBeforeTest, phaseAfterTest)
    34  	}
    35  	return ctx, nil
    36  }
    37  
    38  // runWithFeature executes the feature functions for this action
    39  func (a action) runWithFeature(ctx Context, t *testing.T, feat Feature) (Context, error) {
    40  	switch a.phase {
    41  	case phaseBeforeFeature, phaseAfterFeature:
    42  		for _, f := range a.featureFns {
    43  			var err error
    44  			ctx, err = f(ctx, t, feat)
    45  			if err != nil {
    46  				return ctx, err
    47  			}
    48  		}
    49  	default:
    50  		return ctx, fmt.Errorf("action called for %s, expected [%s, %s]",
    51  			a.phase, phaseBeforeFeature, phaseAfterFeature)
    52  	}
    53  	return ctx, nil
    54  }
    55  
    56  // run executes the framework functions for this action
    57  func (a action) run(ctx Context) (Context, error) {
    58  	for _, f := range a.fns {
    59  		var err error
    60  		ctx, err = f(ctx)
    61  		if err != nil {
    62  			return ctx, err
    63  		}
    64  	}
    65  	return ctx, nil
    66  }
    67  

View as plain text