Skip to content

Commit

Permalink
fix: multilines in args user executor (#565)
Browse files Browse the repository at this point in the history
* fix: multilines in args user executor

close #392

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Aug 4, 2022
1 parent 9a14fda commit ff0f289
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,39 @@ Notice the variable `alljson`. All variables declared in output are automaticall
Venom will load user's executors from the directory `lib/` relative to the testsuite path. You add executors source path using the flag `--lib-dir`.
Note that all folders listed with `--lib-dir` will be scanned recursively to find `.yml` files as user executors.

The user defined executors work with templating, you can check the templating result in `venom.log`. In this file, if you see an error as `error converting YAML to JSON: yaml: line 14: found unexpected end of stream`, you probably need to adjust indentation with the templating function `indent`.

Example:

```yml
name: testsuite with a user executor multilines
testcases:
- name: test
steps:
- type: multilines
script: |
# test multilines
echo "5"
assertions:
- result.alljson ShouldEqual 5
```

using this executor:

```yml
executor: multilines
input:
script: "echo 'foo'"
steps:
- type: exec
script: {{ .input.script | nindent 4 }}
assertions:
- result.code ShouldEqual 0
output:
all: '{{.result.systemoutjson}}'
```


```bash
# lib/*.yml files will be loaded as executors.
$ venom run testsuite.yml
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/multilines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
executor: multilines
input:
script: "bar"
steps:
- type: exec
script: {{ .input.script | nindent 4 }}
assertions:
- result.code ShouldEqual 0
output:
all: '{{.result.systemoutjson}}'
10 changes: 10 additions & 0 deletions tests/multilines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: testsuite with a user executor multilines
testcases:
- name: testA
steps:
- type: multilines
script: |
# test multilines
echo "5"
assertions:
- result.alljson ShouldEqual 5
2 changes: 2 additions & 0 deletions venom.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ func (v *Venom) registerUserExecutors(ctx context.Context, name string, vars map
return errors.Wrapf(err, "unable to parse file %q with content %v", f, content)
}

log.Debugf("User executor %q revolved with content %v", f, content)

for k, vr := range varsComputed {
ux.Input.Add(k, vr)
}
Expand Down

0 comments on commit ff0f289

Please sign in to comment.