Skip to content

Commit

Permalink
adding commits that got missed from a rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Fokion Sotiropoulos <[email protected]>
  • Loading branch information
fokion committed Jul 25, 2023
1 parent 2945a5a commit 0d1dfe3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ func findLineNumber(filename, testcase string, stepNumber int, assertion string,
}

// This evaluates a string of assertions with a given vars scope, and returns a slice of failures (i.e. empty slice = all pass)
func testConditionalStatement(ctx context.Context, tc *TestCase, assertions []string, vars H, text string) ([]string, error) {
func testConditionalStatement(ctx context.Context, tc *TestCase, assertions []string, vars *H, text string) ([]string, error) {
var failures []string
for _, assertion := range assertions {
Debug(ctx, "evaluating %s", assertion)
assert, err := parseAssertions(ctx, assertion, vars)
assert, err := parseAssertions(ctx, assertion, *vars)
if err != nil {
Error(ctx, "unable to parse assertion: %v", err)
return failures, err
Expand Down
14 changes: 9 additions & 5 deletions process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,16 @@ func (v *Venom) processSecrets(ctx context.Context, ts *TestSuite, tc *TestCase)

func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepResult) {
if len(tc.Skip) > 0 {
failures, err := testConditionalStatement(ctx, tc, tc.Skip, tc.Vars, "skipping testcase %q: %v")
failures, err := testConditionalStatement(ctx, tc, tc.Skip, &tc.Vars, "skipping testcase %q: %v")
if err != nil {
Error(ctx, "unable to evaluate \"skip\" assertions: %v", err)
testStepResult := TestStepResult{}
testStepResult.appendError(err)
tc.TestStepResults = append(tc.TestStepResults, testStepResult)
return
}
if len(failures) > 0 {
if failures != nil && len(failures) > 0 {
Info(ctx, fmt.Sprintf("Skipping test case as there are %v failures", len(failures)))
tc.Status = StatusSkip
for _, s := range failures {
tc.Skipped = append(tc.Skipped, Skipped{Value: s})
Expand Down Expand Up @@ -317,7 +318,8 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
v.setTestStepName(tsResult, e, step, &ranged, &rangedData, rangedIndex, printStepName)

// ##### RUN Test Step Here
skip, err := parseSkip(ctx, tc, tsResult, rawStep, stepNumber)
Info(ctx, fmt.Sprintf("Checking skip for test step %v", printStepName))
skip, err := parseSkip(ctx, tc, &stepVars, tsResult, rawStep, stepNumber)
if err != nil {
tsResult.appendError(err)
tsResult.Status = StatusFail
Expand Down Expand Up @@ -430,7 +432,7 @@ func (v *Venom) printTestStepResult(tc *TestCase, ts *TestStepResult, tsIn *Test
}

// Parse and format skip conditional
func parseSkip(ctx context.Context, tc *TestCase, ts *TestStepResult, rawStep []byte, stepNumber int) (bool, error) {
func parseSkip(ctx context.Context, tc *TestCase, vars *H, ts *TestStepResult, rawStep []byte, stepNumber int) (bool, error) {
// Load "skip" attribute from step
var assertions struct {
Skip []string `yaml:"skip"`
Expand All @@ -441,12 +443,14 @@ func parseSkip(ctx context.Context, tc *TestCase, ts *TestStepResult, rawStep []

// Evaluate skip assertions
if len(assertions.Skip) > 0 {
failures, err := testConditionalStatement(ctx, tc, assertions.Skip, tc.computedVars, fmt.Sprintf("skipping testcase %%q step #%d: %%v", stepNumber))
failures, err := testConditionalStatement(ctx, tc, assertions.Skip, vars, fmt.Sprintf("skipping testcase %%q step #%d: %%v", stepNumber))
if err != nil {
Error(ctx, "unable to evaluate \"skip\" assertions: %v", err)
return false, err
}

if len(failures) > 0 {
Info(ctx, fmt.Sprintf("Skip as there are %v failures", len(failures)))
for _, s := range failures {
ts.Skipped = append(ts.Skipped, Skipped{Value: s})
Warn(ctx, s)
Expand Down
21 changes: 12 additions & 9 deletions process_teststep.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,18 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
if assertRes.OK {
break
}
failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), AllVarsFromCtx(ctx), "")
if err != nil {
tsResult.appendError(fmt.Errorf("Error while evaluating retry condition: %v", err))
break
}
if len(failures) > 0 {
failure := newFailure(ctx, *tc, stepNumber, rangedIndex, "", fmt.Errorf("retry conditions not fulfilled, skipping %d remaining retries", e.Retry()-tsResult.Retries))
tsResult.Errors = append(tsResult.Errors, *failure)
break
if len(e.RetryIf()) > 0 {
vars := AllVarsFromCtx(ctx)
failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), &vars, "")
if err != nil {
tsResult.appendError(fmt.Errorf("Error while evaluating retry condition: %v", err))
break
}
if len(failures) > 0 {
failure := newFailure(ctx, *tc, stepNumber, rangedIndex, "", fmt.Errorf("retry conditions not fulfilled, skipping %d remaining retries", e.Retry()-tsResult.Retries))
tsResult.Errors = append(tsResult.Errors, *failure)
break
}
}
}

Expand Down

0 comments on commit 0d1dfe3

Please sign in to comment.