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

Add multi-checker #151

Merged
merged 1 commit into from
Jun 8, 2020
Merged

Add multi-checker #151

merged 1 commit into from
Jun 8, 2020

Conversation

hpidcock
Copy link
Member

@hpidcock hpidcock commented Jun 6, 2020

MultiChecker allows you to perform a DeepEquals but have bespoke checkers based on path matching.

For example, this allows the value at "b" to be ignored.

a1 := map[string]string{"a": "a", "b": "b", "c": "c"}
a2 := map[string]string{"a": "a", "b": "bbbb", "c": "c"}

checker := jc.NewMultiChecker().Add(`["b"]`, jc.Ignore)
c.Check(a1, checker, a2)

This allows the second element to have the SameContents check applied, ignoring order of elements:

a1 := [][]string{{"a", "b", "c"}, {"c", "d", "e"}}
a2 := [][]string{{"a", "b", "c"}, {"e", "c", "d"}}

checker := jc.NewMultiChecker().Add("[1]", jc.SameContents, jc.ExpectedValue)
c.Check(a1, checker, a2)

@hpidcock
Copy link
Member Author

hpidcock commented Jun 7, 2020

!!build!!

3 similar comments
@hpidcock
Copy link
Member Author

hpidcock commented Jun 7, 2020

!!build!!

@hpidcock
Copy link
Member Author

hpidcock commented Jun 7, 2020

!!build!!

@hpidcock
Copy link
Member Author

hpidcock commented Jun 7, 2020

!!build!!

Copy link
Member

@wallyworld wallyworld left a comment

Choose a reason for hiding this comment

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

Nice improvement

// If both values are interface-able and customCheckFunc is non nil,
// customCheckFunc will be invoked. If it returns useDefault as true, the
// DeepEqual continues, otherwise the result of the customCheckFunc is used.
func DeepEqualWithCustomCheck(a1 interface{}, a2 interface{}, customCheckFunc CustomCheckFunc) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

does this need to be exported?

@hpidcock
Copy link
Member Author

hpidcock commented Jun 8, 2020

$$merge$$

@jujubot jujubot merged commit e4eedbc into juju:master Jun 8, 2020
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