Skip to content

Commit

Permalink
Mark test helpers
Browse files Browse the repository at this point in the history
This results in the environment.Test call point being used as the file
and line number in test logs, failures, etc.

Signed-off-by: Nic Cope <[email protected]>
  • Loading branch information
negz committed Jun 3, 2024
1 parent 8f3e893 commit ab485ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/env/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type action struct {

// runWithT will run the action and inject *testing.T into the callback function.
func (a *action) runWithT(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
t.Helper()
switch a.role {
case roleBeforeTest, roleAfterTest:
if cfg.DryRunMode() {
Expand All @@ -98,6 +99,7 @@ func (a *action) runWithT(ctx context.Context, cfg *envconf.Config, t *testing.T

// runWithFeature will run the action and inject a FeatureInfo object into the callback function.
func (a *action) runWithFeature(ctx context.Context, cfg *envconf.Config, t *testing.T, fi types.Feature) (context.Context, error) {
t.Helper()
switch a.role {
case roleBeforeFeature, roleAfterFeature:
if cfg.DryRunMode() {
Expand Down
12 changes: 12 additions & 0 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (e *testEnv) panicOnMissingContext() {
// processTestActions is used to run a series of test action that were configured as
// BeforeEachTest or AfterEachTest
func (e *testEnv) processTestActions(ctx context.Context, t *testing.T, actions []action) context.Context {
t.Helper()
var err error
out := ctx
for _, action := range actions {
Expand All @@ -206,6 +207,7 @@ func (e *testEnv) processTestActions(ctx context.Context, t *testing.T, actions
// workflow of orchestrating the feature execution be running the action configured by BeforeEachFeature /
// AfterEachFeature.
func (e *testEnv) processTestFeature(ctx context.Context, t *testing.T, featureName string, feature types.Feature) context.Context {
t.Helper()
skipped, message := e.requireFeatureProcessing(feature)
if skipped {
t.Skipf(message)
Expand All @@ -223,6 +225,7 @@ func (e *testEnv) processTestFeature(ctx context.Context, t *testing.T, featureN
// processFeatureActions is used to run a series of feature action that were configured as
// BeforeEachFeature or AfterEachFeature
func (e *testEnv) processFeatureActions(ctx context.Context, t *testing.T, feature types.Feature, actions []action) context.Context {
t.Helper()
var err error
out := ctx
for _, action := range actions {
Expand All @@ -241,6 +244,8 @@ func (e *testEnv) processFeatureActions(ctx context.Context, t *testing.T, featu
// In case if the parallel run of test features are enabled, this function will invoke the processTestFeature
// as a go-routine to get them to run in parallel
func (e *testEnv) processTests(ctx context.Context, t *testing.T, enableParallelRun bool, testFeatures ...types.Feature) context.Context {
t.Helper()

if e.cfg.DryRunMode() {
klog.V(2).Info("e2e-framework is being run in dry-run mode. This will skip all the before/after step functions configured around your test assessments and features")
}
Expand Down Expand Up @@ -309,6 +314,7 @@ func (e *testEnv) processTests(ctx context.Context, t *testing.T, enableParallel
// are executed in parallel to avoid duplication of action that might happen
// in BeforeTest and AfterTest actions
func (e *testEnv) TestInParallel(t *testing.T, testFeatures ...types.Feature) context.Context {
t.Helper()
return e.processTests(e.ctx, t, true, testFeatures...)
}

Expand All @@ -325,6 +331,7 @@ func (e *testEnv) TestInParallel(t *testing.T, testFeatures ...types.Feature) co
// BeforeTest and AfterTest operations are executed before and after
// the feature is tested respectively.
func (e *testEnv) Test(t *testing.T, testFeatures ...types.Feature) context.Context {
t.Helper()
return e.processTests(e.ctx, t, false, testFeatures...)
}

Expand Down Expand Up @@ -437,6 +444,7 @@ func (e *testEnv) getFinishActions() []action {
}

func (e *testEnv) executeSteps(ctx context.Context, t *testing.T, steps []types.Step) context.Context {
t.Helper()
if e.cfg.DryRunMode() {
return ctx
}
Expand All @@ -447,8 +455,11 @@ func (e *testEnv) executeSteps(ctx context.Context, t *testing.T, steps []types.
}

func (e *testEnv) execFeature(ctx context.Context, t *testing.T, featName string, f types.Feature) context.Context {
t.Helper()
// feature-level subtest
t.Run(featName, func(newT *testing.T) {
newT.Helper()

if fDescription, ok := f.(types.DescribableFeature); ok && fDescription.Description() != "" {
t.Logf("Processing Feature: %s", fDescription.Description())
}
Expand All @@ -473,6 +484,7 @@ func (e *testEnv) execFeature(ctx context.Context, t *testing.T, featName string
// If it is, we won't proceed with the next assessment.
var shouldFailNow bool
newT.Run(assessName, func(internalT *testing.T) {
internalT.Helper()
skipped, message := e.requireAssessmentProcessing(assess, i+1)
if skipped {
internalT.Skipf(message)
Expand Down

0 comments on commit ab485ba

Please sign in to comment.