Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault committed Nov 23, 2020
1 parent 2ea9190 commit 745da9c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
3 changes: 3 additions & 0 deletions assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ func applyAssertions(r interface{}, tc TestCase, stepNumber int, step TestStep,

executorResult := GetExecutorResult(r)

fmt.Printf("###### ---> executorResult: %+v\n", executorResult)

isOK := true
for _, assertion := range sa.Assertions {
fmt.Printf("###### ---> assertion: %+v executorResult:%+v\n", assertion, executorResult)
errs, fails := check(tc, stepNumber, assertion, executorResult)
if errs != nil {
errors = append(errors, *errs)
Expand Down
2 changes: 1 addition & 1 deletion process_teststep.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
continue
}

Debug(ctx, "result: %+v", result)
Debug(ctx, "result of runTestStepExecutor: %+v", result)
mapResult := GetExecutorResult(result)
mapResultString, _ := executors.DumpString(result)

Expand Down
4 changes: 2 additions & 2 deletions tests/lib/customA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ steps:
assertions:
- result.code ShouldEqual 0
output:
systemout: "{{.result.systemout}}"
systemoutjson.hello: "{{.result.systemoutjson.hello}}"
systemoutjson:
hello: "{{.result.systemoutjson.hello}}"
7 changes: 6 additions & 1 deletion tests/user_executor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ name: testsuite with a user executor
testcases:
- name: testA
steps:
- script: echo "{\"hello\":\"bar\"}"
info:
- result of customA is {{.result.systemoutjson.hello}}
- type: customA
myarg: World
info:
- result of customA is {{.result.systemoutjson.hello}}
- result of customA is result.systemoutjson.hello --> {{.result.systemoutjson.hello}}
- result of customA is systemoutjson.hello --> {{.systemoutjson.hello}}
- result of customA is result --> {{.result}}
assertions:
- result.systemoutjson.hello ShouldContainSubstring World
32 changes: 18 additions & 14 deletions types_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/fsamin/go-dump"
"github.com/ghodss/yaml"
"github.com/gosimple/slug"
"github.com/ovh/cds/sdk/interpolate"
"github.com/ovh/venom/executors"
Expand Down Expand Up @@ -145,7 +146,7 @@ type UserExecutor struct {
Executor string `json:"executor" yaml:"executor"`
Input H `json:"input" yaml:"input"`
RawTestSteps []json.RawMessage `json:"steps" yaml:"steps"`
Output H `json:"output" yaml:"output"`
Output json.RawMessage `json:"output" yaml:"output"`
}

func (ux UserExecutor) Run(ctx context.Context, step TestStep) (interface{}, error) {
Expand Down Expand Up @@ -188,27 +189,30 @@ func (v *Venom) RunUserExecutor(ctx context.Context, ux UserExecutor, step TestS

v.runTestSteps(ctx, tc)

result := H{}
computedVars, err := dump.ToStringMap(tc.computedVars)
if err != nil {
return nil, errors.Wrapf(err, "unable to dump testcase computedVars")
}
uxOutput, err := dump.ToStringMap(ux.Output)

type Output struct {
Result json.RawMessage `json:"result"`
}
output := Output{
Result: ux.Output,
}
outputString, err := json.Marshal(output)
if err != nil {
return nil, errors.Wrapf(err, "unable to dump user executor output")
return nil, err
}

for k, va := range uxOutput {
if _, ok := computedVars["result."+k]; ok {
content, err := interpolate.Do(va, computedVars)
if err != nil {
return nil, err
}
Debug(ctx, "add result.%v : %v", k, content)
result.AddWithPrefix("result", k, content)
}
outputS, err := interpolate.Do(string(outputString), computedVars)
if err != nil {
return nil, err
}

var result interface{}
if err := yaml.Unmarshal([]byte(outputS), &result); err != nil {
return nil, errors.Wrapf(err, "unable to unmarshal output")
}
if len(tc.Errors) > 0 || len(tc.Failures) > 0 {
return result, fmt.Errorf("failed")
}
Expand Down

0 comments on commit 745da9c

Please sign in to comment.