canonical / pebble

Take control of your internal daemons!
https://canonical-pebble.readthedocs-hosted.com/
GNU General Public License v3.0
143 stars 54 forks source link

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

Closed dmitry-lyfar closed 9 months ago

dmitry-lyfar commented 9 months ago

This PR is made in preparation to merge the latest snapd state package changes into pebble as per the plan discussed in https://github.com/canonical/pebble/pull/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).

benhoyt commented 9 months ago

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.

dmitry-lyfar commented 9 months ago

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).