-
Notifications
You must be signed in to change notification settings - Fork 127
internal/testrunner/runners/pipeline: replace jsondiff output with difflib #872
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
Conversation
🌐 Coverage report
|
…fflib This gives a correct output for arrays and provides meaningful context for finding issues in test-case source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with the general approach to change the diff that is printed. Added some questions.
|
|
||
| // Configure diff. | ||
| opts.SkipMatches = true | ||
| opts.CompareNumbers = compareJsonNumbers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compareJsonNumbers and its test can be removed if we stop using jsondiff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was originally thinking that, but the logic behind using it made a lot of sense, to I used it as the Comparer for cmp.Equal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you are right, I didn't see that it was still used there 👍
| return "", nil | ||
| } | ||
|
|
||
| result, diff := jsondiff.Compare(want, got, &opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could keep this comparison method even if later we change the diff that we print, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's right.
| return "", err | ||
| } | ||
| return diff, nil | ||
| want, err = marshalNormalizedJSON(wantVal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marshalNormalizedJSON marshals and unmarshals using jsonUnmarshalUsingNumber, something that has been already done here. We could do the final marshal directly here instead of repeating the operations.
Not so important though as this code is only used if the documents are different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was being conservative to ensure that the values were being treated the same way and to ensure that the reader was clear that this was happening.
|
|
||
| // Configure diff. | ||
| opts.SkipMatches = true | ||
| opts.CompareNumbers = compareJsonNumbers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you are right, I didn't see that it was still used there 👍
This gives a correct output for arrays and provides meaningful context for finding issues in test-case source. (Note also that this is the library that is used in beats for diff output).
Please take a look.