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

feat(testutil): add ErrorIs and DeepUnsortedMatches checkers #331

Merged

Conversation

dmitry-lyfar
Copy link
Contributor

@dmitry-lyfar dmitry-lyfar commented Nov 17, 2023

This PR is made in preparation to merge the latest snapd state package changes into pebble as per the plan discussed in #259.

Both ErrorIs and DeepUnsortedMatches checkers are used by the latest state package test suites. These are cherry-picked from the snapd repository with some minor changes (fixed Pebble linter's warnings, updated license header).

Adds a Checker to test that two containers have the same elements (duplicates must occur in the same number) but possibly in different orders.
@benhoyt
Copy link
Contributor

benhoyt commented Nov 19, 2023

Thanks @dmitry-lyfar. I'm wondering why there are differences (other than minor changes). Specifically, snapd's version of DeepUnsortedMatches has a deepMapMatch function as part of the implementation, and also uses validateContainerTypesAndLengths. See for example https://github.com/snapcore/snapd/blob/89cdb0c45be1b28b161653b5164dbd74dd3ef70d/testutil/containschecker.go#L182-L192

The ErrorIs checker only seems to have minor modifications.

MiguelPires and others added 2 commits November 21, 2023 11:35
Only top-level containers were matched in an unsorted way and maps
were compared with reflect.DeepEqual. Now map values are also "unsorted
matched" so values like map[string][]string can be compared regardless
of order even with nesting. Note that containers nested in slices or
arrays are still compared in the normal way.

Signed-off-by: Miguel Pires <[email protected]>
(cherry picked from commit 1af63c24476cb0a7409d499a76c8b5a59c04ca9c)
As suggested by staticcheck.io

(cherry picked from commit 4eff3617d9d1152874db2a2f8b6d90678f59c6b1)
@dmitry-lyfar
Copy link
Contributor Author

Thanks @dmitry-lyfar. I'm wondering why there are differences (other than minor changes). Specifically, snapd's version of DeepUnsortedMatches has a deepMapMatch function as part of the implementation, and also uses validateContainerTypesAndLengths. See for example https://github.com/snapcore/snapd/blob/89cdb0c45be1b28b161653b5164dbd74dd3ef70d/testutil/containschecker.go#L182-L192

The ErrorIs checker only seems to have minor modifications.

Thanks. Fixed, including the latest static check updates for the ErrorIs checker. Sorry, I must have failed to track the entire commit history for these changes for some reason (had them in the original PR).

Copy link
Contributor

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks!

@benhoyt benhoyt changed the title Add ErrorIs and DeepUnsortedMatches checkers to the testutil package feat(testutil): add ErrorIs and DeepUnsortedMatches checkers Nov 20, 2023
@benhoyt benhoyt merged commit 70f3ad1 into canonical:master Nov 20, 2023
15 checks passed
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.

4 participants