goss-org / goss

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

Added: Initial diff support #827

Closed aelsabbahy closed 11 months ago

aelsabbahy commented 11 months ago
Checklist

Description of change

Adds unified diff to the output when doing string comparison. For example:

$ cat test.txt 
this is a file
containing
hello world

$ cat goss.yaml 
file:
  test.txt:
    exists: true
    mode: "0664"
    owner: aelsabbahy
    group: aelsabbahy
    filetype: file
    contents: |
      this is a file
      containing
      goodbye world

$ goss v
.....F

Failures/Skipped:

File: test.txt: contents:
Expected
    "this is a file\ncontaining\nhello world\n"
to equal
    "this is a file\ncontaining\ngoodbye world\n"
diff
    --- test
    +++ actual
    @@ -1,3 +1,3 @@
     this is a file
     containing
    -goodbye world
    +hello world

Total Duration: 0.000s
Count: 6, Failed: 1, Skipped: 0

The current implementation only does it for multi-line assertions, but I think that might be unnecessarily clever.. not sure.

For example, changing the above goss.yaml to only match one line will behave differently:

$ cat goss.yaml 
file:
  test.txt:
    exists: true
    mode: "0664"
    owner: aelsabbahy
    group: aelsabbahy
    filetype: file
    contents: |
      goodbye world

$ goss v
.....F

Failures/Skipped:

File: test.txt: contents:
Expected
    "this is a file\ncontaining\nhello world\n"
to equal
    "goodbye world\n"

Total Duration: 0.000s
Count: 6, Failed: 1, Skipped: 0
aelsabbahy commented 11 months ago

Decided to go with always showing the diff when the strings don't match. Principal of least surprise and all..