Skip to content

Conversation

@efd6
Copy link
Contributor

@efd6 efd6 commented Jun 27, 2022

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.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jun 28, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-06-28T01:30:00.427+0000

  • Duration: 28 min 32 sec

Test stats 🧪

Test Results
Failed 0
Passed 742
Skipped 0
Total 742

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jun 28, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (31/31) 💚
Files 66.071% (74/112) 👍
Classes 61.146% (96/157) 👍
Methods 49.126% (309/629) 👍
Lines 33.021% (2784/8431) 👎 -0.047
Conditionals 100.0% (0/0) 💚

…fflib

This gives a correct output for arrays and provides meaningful context for finding
issues in test-case source.
@jsoriano jsoriano self-requested a review June 28, 2022 09:48
Copy link
Member

@jsoriano jsoriano left a 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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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 👍

@efd6 efd6 merged commit c6a6d36 into elastic:main Jun 28, 2022
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.

3 participants