diff --git a/assertion_test.go b/assertion_test.go index 4f1cd865..543195ea 100644 --- a/assertion_test.go +++ b/assertion_test.go @@ -1,6 +1,8 @@ package venom import ( + "context" + "github.com/ovh/venom/assertions" "reflect" "testing" ) @@ -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") + } +} diff --git a/process_testcase.go b/process_testcase.go index 4cb08825..e9a79ab2 100644 --- a/process_testcase.go +++ b/process_testcase.go @@ -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{}{} @@ -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) } @@ -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) } diff --git a/process_teststep.go b/process_teststep.go index 2273cf0c..07f5647f 100644 --- a/process_teststep.go +++ b/process_teststep.go @@ -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 + } } } diff --git a/tests/skip/skip-testcase.yml b/tests/skip/skip-testcase.yml new file mode 100644 index 00000000..cdf28a07 --- /dev/null +++ b/tests/skip/skip-testcase.yml @@ -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 + diff --git a/tests/skip/skip.yml b/tests/skip/skip.yml new file mode 100644 index 00000000..b5aef33a --- /dev/null +++ b/tests/skip/skip.yml @@ -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