goss-org / goss

Quick and Easy server testing/validation
https://goss.rocks
Apache License 2.0
5.62k stars 472 forks source link

New --exact-match option to "goss add command" to perform exact multi-line matches #947

Open gberche-orange opened 4 months ago

gberche-orange commented 4 months ago

Describe the feature:

Enable goss add command to capture stdout/stderr as a multiline script

This enables to capture & then validate various multiline outputs that are sensitive to space and linefeed (typically yaml output).

This is useful in the test approach sometimes called golden master testing / approval testing/ Characterization tests see https://en.wikipedia.org/wiki/Characterization_test

Here is a sample library that that supports such practice https://approvaltests.com/

Currently, the goss add command does a great job at capturing by default an array of trimmed strings to match. But this can not be used for approval testing commands that produce yaml.

Describe the solution you'd like

A new --exact-match option to "goss add command" to perform exact multi-line matches

Describe alternatives you've considered

wrap goss add with a script which would replace using yq the command.cmd.stdout

aelsabbahy commented 2 months ago

Makes sense, marked as approved. I'll accept a PR implementing this. Can also be useful for the http check.