diff --git a/README.md b/README.md index 4adf88cb..13a0d49c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tests/lib/multilines.yml b/tests/lib/multilines.yml new file mode 100644 index 00000000..184458de --- /dev/null +++ b/tests/lib/multilines.yml @@ -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}}' diff --git a/tests/multilines.yml b/tests/multilines.yml new file mode 100644 index 00000000..6bb65836 --- /dev/null +++ b/tests/multilines.yml @@ -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 \ No newline at end of file diff --git a/venom.go b/venom.go index f07e524f..dcbff2f1 100644 --- a/venom.go +++ b/venom.go @@ -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) }