Closed goharma closed 1 month ago
Here ist an example of using a list. You need the range
.
https://github.com/bitnami/containers/blob/main/.vib/common/goss/templates/check-binaries.yaml
Thank you
I added [] to the contents and it works. Thanks again.
file: {{ range $item := .Vars.my_list }} my_file-{{ $item }}: path: my_file exists: true contents: [ {{ $item }} ] {{ end }}
Not sure if I have something wrong, but I'm still getting errors.
file: {{ range $item := .Vars.my_list }} my_file-{{ $item }}: path: my_file exists: true contents: {{ $item }} {{ end }}
my_list:
one two
.F.F
Failures/Skipped:
File: my_file-one: my_file: contents: Expected "one\ntwo" to equal "one" diff --- test +++ actual @@ -1 +1,2 @@ one +two
File: my_file-two: my_file: contents: Expected "one\ntwo" to equal "two" diff --- test +++ actual @@ -1 +1,2 @@ +one two
Total Duration: 0.001s Count: 4, Failed: 2, Skipped: 0
Thank you @dklimpel !
Anyone reading this issue, feel free to submit a PR improving the documentation if you feel it will help.
Is there a way to pass in a list as a variable?
SCENARIO 1:
GOSSFILE: file: my_file: exists: true contents: "{{ .Vars.my_list }}"
VARS FILE: my_list:
EXECUTION
goss -g test_goss.yaml --vars test_vars.yaml v .F
Failures/Skipped:
File: my_file: contents: Expected "one\ntwo\n" to equal "[one two]" diff --- test +++ actual @@ -1 +1,3 @@ -[one two] +one +two +
Total Duration: 0.001s Count: 2, Failed: 1, Skipped: 0
SCENARIO 2:
GOSSFILE: file: my_file: exists: true contents: ${.Vars.my_list}
VARS FILE: my_list:
EXECUTION
goss -g test_goss.yaml --vars test_vars.yaml v .F
Failures/Skipped:
File: my_file: contents: Expected "one\ntwo\n" to equal "${.Vars.my_list}" diff --- test +++ actual @@ -1 +1,3 @@ -${.Vars.my_list} +one +two +
Total Duration: 0.001s Count: 2, Failed: 1, Skipped: 0