Skip to content

Commit

Permalink
Update the skip as it was not working correctly
Browse files Browse the repository at this point in the history
It could not evaluate a variable that was defined on previous steps and during processing we should check that the failures are empty

Signed-off-by: Fokion Sotiropoulos <[email protected]>
  • Loading branch information
fokion committed Jun 19, 2023
1 parent 8132d17 commit f15a042
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
13 changes: 13 additions & 0 deletions assertion_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package venom

import (
"context"
"github.com/ovh/venom/assertions"
"reflect"
"testing"
)
Expand All @@ -22,3 +24,14 @@ func Test_splitAssertion(t *testing.T) {
}
}
}

func Test_parseAssertions(t *testing.T) {
vars := make(map[string]string)
vars["out"] = "2"
assertion, err := parseAssertions(context.Background(), "out ShouldEqual '2'", vars)
_ = assertions.ShouldNotBeNil(&assertion)
e := assertions.ShouldBeNil(err)
if e != nil {
t.Errorf("The err should be nil")
}
}
7 changes: 3 additions & 4 deletions process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe

tsResult.End = time.Now()
tsResult.Duration = tsResult.End.Sub(tsResult.Start).Seconds()

tc.testSteps = append(tc.testSteps, step)
}

Expand Down Expand Up @@ -429,13 +428,13 @@ func parseSkip(ctx context.Context, tc *TestCase, ts *TestStepResult, rawStep []

// Evaluate skip assertions
if len(assertions.Skip) > 0 {
results, err := testConditionalStatement(ctx, tc, assertions.Skip, tc.Vars, fmt.Sprintf("skipping testcase %%q step #%d: %%v", stepNumber))
failures, err := testConditionalStatement(ctx, tc, assertions.Skip, tc.computedVars, 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(results) > 0 {
for _, s := range results {
if len(failures) == 0 {
for _, s := range failures {
ts.Skipped = append(ts.Skipped, Skipped{Value: s})
Warn(ctx, s)
}
Expand Down
2 changes: 1 addition & 1 deletion process_teststep.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
if assertRes.OK {
break
}
failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), tsResult.ComputedVars, "")
failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), AllVarsFromCtx(ctx), "")
if err != nil {
tsResult.appendError(fmt.Errorf("Error while evaluating retry condition: %v", err))
break
Expand Down
30 changes: 30 additions & 0 deletions tests/skip/skip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name : "Testing skip"
testcases:
- name : "do not skip"
steps:
- info : Hello
- name : "skip something"

steps:
- info:
- Hello
- script : "echo '1'"
vars :
out:
from : result.systemout
- info:
- "do not skip it as it is different"
skip :
- out ShouldEqual '2'
- script: "echo 'false'"
vars:
outAsBool:
from: result.systemout
- info:
- "Fail should be skipped"
skip :
- out ShouldEqual 1
- info:
- "Fail should be skipped as false"
skip:
- outAsBool ShouldBeFalse

0 comments on commit f15a042

Please sign in to comment.