Skip to content

Commit

Permalink
fix: revert #617 (#636)
Browse files Browse the repository at this point in the history
* Revert "feat: removed result from testcase variables and removed errors warning and info from non verbose runs (#617)"

This reverts commit 0d936bf.

* fix: revert #617

Signed-off-by: Yvonnick Esnault <[email protected]>

* Update interpolate_once.yml

---------

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Feb 15, 2023
1 parent 0d936bf commit 4964f01
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 46 deletions.
65 changes: 35 additions & 30 deletions process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
} else {
tsResult.Start = time.Now()
tsResult.Status = StatusRun
v.RunTestStep(ctx, e, tc, tsResult, stepNumber, rangedIndex, step)
result := v.RunTestStep(ctx, e, tc, tsResult, stepNumber, rangedIndex, step)
if len(tsResult.Errors) > 0 || !tsResult.AssertionsApplied.OK {
tsResult.Status = StatusFail
} else {
Expand All @@ -322,6 +322,9 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
tsResult.End = time.Now()
tsResult.Duration = tsResult.End.Sub(tsResult.Start).Seconds()

mapResult := GetExecutorResult(result)
previousStepVars.AddAll(H(mapResult))

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

Expand All @@ -337,16 +340,17 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
if isRequired {
failure := newFailure(ctx, *tc, stepNumber, rangedIndex, "", fmt.Errorf("At least one required assertion failed, skipping remaining steps"))
tsResult.appendFailure(*failure)
v.printTestStepResult(tc, tsResult, tsIn, stepNumber, true)
v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, true)
return
}
v.printTestStepResult(tc, tsResult, tsIn, stepNumber, false)
v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, false)
continue
}
v.printTestStepResult(tc, tsResult, tsIn, stepNumber, false)
v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, false)

allVars := tc.Vars.Clone()
allVars.AddAll(tsResult.ComputedVars.Clone())
allVars.AddAll(tc.computedVars.Clone())
tsResult.ComputedVars = tc.computedVars.Clone()

assign, _, err := processVariableAssignments(ctx, tc.Name, allVars, rawStep)
if err != nil {
Expand All @@ -371,42 +375,43 @@ func (v *Venom) setTestStepName(ts *TestStepResult, e ExecutorRunner, step TestS
}
}
if ranged.Enabled {
if rangedIndex == 0 {
v.Print("\n")
}
name = fmt.Sprintf("%s (range=%s)", name, rangedData.Key)
}
ts.Name = name

if print {
if print || ranged.Enabled {
v.Print(" \t\t• %s", ts.Name)
}
}

// Print a single step result (if verbosity is enabled)
func (v *Venom) printTestStepResult(tc *TestCase, ts *TestStepResult, tsIn *TestStepResult, stepNumber int, mustAssertionFailed bool) {
if tsIn != nil {
func (v *Venom) printTestStepResult(tc *TestCase, ts *TestStepResult, tsIn *TestStepResult, ranged Range, stepNumber int, mustAssertionFailed bool) {
fromUserExecutor := tsIn != nil
if fromUserExecutor {
tsIn.appendFailure(ts.Errors...)
} else if v.Verbose >= 1 {
if len(ts.Errors) > 0 {
v.Println(" %s", Red(StatusFail))
for _, i := range ts.ComputedInfo {
v.Println(" \t\t %s %s", Cyan("[info]"), Cyan(i))
}
for _, f := range ts.Errors {
v.Println(" \t\t %s", Yellow(f.Value))
}
if mustAssertionFailed {
skipped := len(tc.RawTestSteps) - stepNumber - 1
if skipped == 1 {
v.Println(" \t\t %s", Gray(fmt.Sprintf("%d other step was skipped", skipped)))
} else {
v.Println(" \t\t %s", Gray(fmt.Sprintf("%d other steps were skipped", skipped)))
}
if ranged.Enabled || v.Verbose >= 1 {
if !fromUserExecutor { //Else print step status
if len(ts.Errors) > 0 {
v.Println(" %s", Red(StatusFail))
for _, f := range ts.Errors {
v.Println(" \t\t %s", Yellow(f.Value))
}
}
} else if ts.Status == StatusSkip {
v.Println(" %s", Gray(StatusSkip))
} else {
v.Println(" %s", Green(StatusPass))
for _, i := range ts.ComputedInfo {
v.Println(" \t\t %s %s", Cyan("[info]"), Cyan(i))
if mustAssertionFailed {
skipped := len(tc.RawTestSteps) - stepNumber - 1
if skipped == 1 {
v.Println(" \t\t %s", Gray(fmt.Sprintf("%d other step was skipped", skipped)))
} else {
v.Println(" \t\t %s", Gray(fmt.Sprintf("%d other steps were skipped", skipped)))
}
}
} else if ts.Status == StatusSkip {
v.Println(" %s", Gray(StatusSkip))
} else {
v.Println(" %s", Green(StatusPass))
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions process_teststep.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type dumpFile struct {
}

// RunTestStep executes a venom testcase is a venom context
func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase, tsResult *TestStepResult, stepNumber int, rangedIndex int, step TestStep) {
func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase, tsResult *TestStepResult, stepNumber int, rangedIndex int, step TestStep) interface{} {
ctx = context.WithValue(ctx, ContextKey("executor"), e.Name())

var assertRes AssertionsApplied
Expand Down Expand Up @@ -65,8 +65,7 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
filename := path.Join(oDir, fmt.Sprintf("%s.%s.step.%d.%d.dump.json", slug.Make(StringVarFromCtx(ctx, "venom.testsuite.shortName")), slug.Make(tc.Name), stepNumber, rangedIndex))

if err := os.WriteFile(filename, []byte(output), 0644); err != nil {
Error(ctx, "Error while creating file %s: %v", filename, err)
return
return fmt.Errorf("Error while creating file %s: %v", filename, err)
}
tc.computedVerbose = append(tc.computedVerbose, fmt.Sprintf("writing %s", filename))
}
Expand All @@ -93,6 +92,7 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
}
}
Info(ctx, info)
tc.computedInfo = append(tc.computedInfo, info)
tsResult.ComputedInfo = append(tsResult.ComputedInfo, info)
}

Expand All @@ -108,12 +108,12 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
}

tsResult.AssertionsApplied = assertRes
tsResult.ComputedVars.AddAll(H(mapResult))
tc.computedVars.AddAll(H(mapResult))

if assertRes.OK {
break
}
failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), tsResult.ComputedVars, "")
failures, err := testConditionalStatement(ctx, tc, e.RetryIf(), tc.computedVars, "")
if err != nil {
tsResult.appendError(fmt.Errorf("Error while evaluating retry condition: %v", err))
break
Expand All @@ -133,6 +133,8 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,

tsResult.Systemerr += assertRes.systemerr + "\n"
tsResult.Systemout += assertRes.systemout + "\n"

return result
}

func (v *Venom) runTestStepExecutor(ctx context.Context, e ExecutorRunner, tc *TestCase, ts *TestStepResult, step TestStep) (interface{}, error) {
Expand Down
18 changes: 8 additions & 10 deletions process_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (v *Venom) runTestCases(ctx context.Context, ts *TestSuite) {

// Verbose mode already reported tests status, so just print them when non-verbose
indent := ""
if verboseReport {
if hasRanged || verboseReport {
indent = "\t "
// If the testcase was entirely skipped, then the verbose mode will not have any output
// Print something to inform that the testcase was indeed processed although skipped
Expand All @@ -163,21 +163,19 @@ func (v *Venom) runTestCases(ctx context.Context, ts *TestSuite) {
}
}

for _, i := range tc.computedInfo {
v.Println("\t %s%s %s", indent, Cyan("[info]"), Cyan(i))
}

for _, i := range tc.computedVerbose {
v.PrintlnIndentedTrace(i, indent)
}

// Verbose mode already reported failures, so just print them when non-verbose
if !verboseReport && hasFailure {
if !hasRanged && !verboseReport && hasFailure {
for _, testStepResult := range tc.TestStepResults {
if len(testStepResult.ComputedInfo) > 0 || len(testStepResult.Errors) > 0 {
v.Println(" \t\t• %s", testStepResult.Name)
for _, f := range testStepResult.ComputedInfo {
v.Println(" \t\t %s", Cyan(f))
}
for _, f := range testStepResult.Errors {
v.Println(" \t\t %s", Yellow(f.Value))
}
for _, f := range testStepResult.Errors {
v.Println("%s", Yellow(f.Value))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/interpolate_once.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ testcases:
script: "echo myvar {{.randomvar}}"
info: "{{.result.systemout}}"
assertions:
- result.systemout ShouldContainSubstring "{{.myvar_first.result.systemout}}"
- result.systemout ShouldContainSubstring "{{.myvar_first.result.systemout}}"
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type TestCase struct {
TestSuiteVars H `json:"-" yaml:"-"`

computedVars H `json:"-" yaml:"-"`
computedInfo []string `json:"-" yaml:"-"`
computedVerbose []string `json:"-" yaml:"-"`
IsExecutor bool `json:"-" yaml:"-"`
IsEvaluated bool `json:"-" yaml:"-"`
Expand Down
4 changes: 4 additions & 0 deletions types_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ func (v *Venom) RunUserExecutor(ctx context.Context, runner ExecutorRunner, tcIn
return nil, err
}

// re-inject info into executorRunner
b := runner.(*executor)
b.info = append(b.info, tc.computedInfo...)

var outputResult interface{}
if err := yaml.Unmarshal([]byte(outputS), &outputResult); err != nil {
return nil, errors.Wrapf(err, "unable to unmarshal")
Expand Down

0 comments on commit 4964f01

Please sign in to comment.