Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Initial diff support #827

Merged
merged 6 commits into from
Aug 7, 2023
Merged

Added: Initial diff support #827

merged 6 commits into from
Aug 7, 2023

Conversation

aelsabbahy
Copy link
Member

@aelsabbahy aelsabbahy commented Aug 5, 2023

Checklist
  • make test-all (UNIX) passes. CI will also test this
  • unit and/or integration tests are included (if applicable)
  • documentation is changed or added (if applicable)

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 aelsabbahy requested a review from ripienaar August 5, 2023 16:56
@aelsabbahy
Copy link
Member Author

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

@aelsabbahy aelsabbahy merged commit 4ac6db0 into master Aug 7, 2023
@aelsabbahy aelsabbahy deleted the string_match_enhancement branch August 7, 2023 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant