Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the skip as it was not working correctly #685

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}
37 changes: 19 additions & 18 deletions process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,23 @@ func (v *Venom) processSecrets(ctx context.Context, ts *TestSuite, tc *TestCase)
}

func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepResult) {
results, 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(results) > 0 {
tc.Status = StatusSkip
for _, s := range results {
tc.Skipped = append(tc.Skipped, Skipped{Value: s})
Warn(ctx, s)
if len(tc.Skip) > 0 {
results, 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(results) == 0 {
tc.Status = StatusSkip
for _, s := range results {
tc.Skipped = append(tc.Skipped, Skipped{Value: s})
Warn(ctx, s)
}
return
}
return
}

var knowExecutors = map[string]struct{}{}
Expand Down Expand Up @@ -333,7 +335,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 @@ -440,13 +441,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
20 changes: 11 additions & 9 deletions process_teststep.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
if assertRes.OK {
break
}
failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), tsResult.ComputedVars, "")
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{
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
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/skip/skip-testcase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name : "Testing skip"
testcases:
- name : "producer"
steps:
- info:
- Set a variable to 1
- script : "echo '1'"
vars :
out:
from : result.systemout
- name: "consumer"
skip:
- producer.out ShouldEqual 1
step:
- info:
- "Fail should be skipped"
script: |
exit 1

35 changes: 35 additions & 0 deletions tests/skip/skip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name : "Testing skip"
testcases:
- name : "skip something"
steps:
- info:
- Set a variable to 1
- script : "echo '1'"
vars :
out:
from : result.systemout
- info:
- "do not skip it as the value of out is different to 2"
skip :
- out ShouldEqual '2'
- name: skip-this
script: |
exit 1
skip:
- out ShouldEqual '1'
- script: "echo 'false'"
vars:
outAsBool:
from: result.systemout
- info:
- "Fail should be skipped"
script: |
exit 1
skip :
- out ShouldEqual 1
- info:
- "Fail should be skipped as false"
script: |
exit 1
skip:
- outAsBool ShouldBeFalse