Closed smerle33 closed 4 months ago
Does the documentation here help?
https://github.com/goss-org/goss/blob/master/docs/manual.md#ioreaders
As I understand your request, you would like "18.18.2" to be a partial match
Do you want the not to be a partial match or exact match?
Does the documentation here help?
not really, I did try :
---
command:
bundle:
exec: bundle -v
exit-status: 0
nodejs:
exec: node --version
exit-status: 0
stdout:
and:
- contain-element: "18.18.2"
- not: {contain-element: "Please install a version by running one of the following"}
npm:
exec: npm version
exit-status: 0
but got :
Failures/Skipped:
Command: nodejs: stdout:
Expected
["v18.18.2",""]
to contain element matching
"18.18.2"
the transform chain was
[{"to-array":{}}]
the raw value was
"v18.18.2\n"
As I understand your request, you would like "18.18.2" to be a partial match
Do you want the not to be a partial match or exact match?
both should be partial.
my main problem here is that if the nodejs is not installed, the asdf dump an informationnal text that contain the version, so if I just look for it, goss give a false positif.
I need to search the version (partial as I don't want to deal with v
and \n
and that the text Please install a version by running one of the following
is NOT present :
Please install a version by running one of the following:
asdf install nodejs 18.15.0
or add one of the following versions in your config file at /Users/smerle/code/infra-reports/.tool-versions
nodejs 18.18.2
If I'm understanding your request correctly, the test can simply be:
command:
nodejs:
exec: node --version
exit-status: 0
stdout:
- '18.18.2'
- '!Please install a version by running one of the following'
Here's an example I tested with locally (just used cat and stubbed data to reproduce your requirements):
Stubs:
$ tail 872_*
==> 872_bad1.txt <==
Please install a version by running one of the following:
asdf install nodejs 18.15.0
or add one of the following versions in your config file at /Users/smerle/code/infra-reports/.tool-versions
nodejs 18.18.2
==> 872_bad2.txt <==
v18.18.9999
==> 872_good.txt <==
v18.18.2
goss.yaml:
$ cat goss.yaml
command:
cat 872_bad1.txt:
exit-status: 0
stdout:
- '18.18.2'
- '!Please install a version by running one of the following'
cat 872_bad2.txt:
exit-status: 0
stdout:
- '18.18.2'
- '!Please install a version by running one of the following'
cat 872_good.txt:
exit-status: 0
stdout:
- '18.18.2'
- '!Please install a version by running one of the following'
results:
$ goss v
...F.F
Failures/Skipped:
Command: cat 872_bad1.txt: stdout:
Expected
"object: *bytes.Reader"
to have patterns
["18.18.2","!Please install a version by running one of the following"]
the missing elements were
["!Please install a version by running one of the following"]
Command: cat 872_bad2.txt: stdout:
Expected
"object: *bytes.Reader"
to have patterns
["18.18.2","!Please install a version by running one of the following"]
the missing elements were
["18.18.2"]
Total Duration: 0.005s
Count: 6, Failed: 2, Skipped: 0
The documentation has a mistake for the expanded version, you're correct it will match the whole string. To get the same result as above using and
+ contain-element
you need to add a contain-substring
:
stdout:
and:
- contain-element:
contain-substring: '18.18.2'
- not:
contain-element:
contain-substring: 'Please install a version by running one of the following'
Hope this helps, sorry for the delay, wanted to respond from a computer to provide a thorough answer.
this :
stdout:
- '18.18.2'
- '!Please install a version by running one of the following'
worked perfectly ! Thanks for your help
(this not :
stdout:
and:
- contain-element:
contain-substring: '18.18.2'
- not:
contain-element:
contain-substring: 'Please install a version by running one of the following'
)
I cannot have, in the command part, a 2 steps test with contain AND not contain string
I got :
or
this one check the exact "18.18.2" and not the contain :
while if I drop the AND it correctly check the content .... but I would miss the NOT part
Expected Behavior I would like the AND to keep the check as without it meaning if the stdout
contain
the string (i would expect an exact match with quotes for example) I would like the NOT to work like here : https://github.com/goss-org/goss/blob/9ae6acfa7a895b5b89ef8088afe55accbf08fc12/examples/goss_awesome_gomega.yaml#L41Actual Behavior doesn't work at all.
Environment: