I am using BeComparableTo with IgnoreUnset, a helper function from k8s.io/apimachinery that "ignores fields that are unset on the right hand side of a comparison". This option is very helpful to check that a struct is a derivative of another struct.
When using it, the "Match" function behave correctly, so if everything is as it should be it does not error, but if something is not, the failure message show differences that should be ignored by the option.
I think the issue is that the option I use "ignores fields that are unset on the right hand side of a comparison", and that (note the difference in order between actual and matcher.Expected):
the function Match returns cmp.Equal(actual, matcher.Expected, matcher.Options...)
the function FailureMessage returns cmp.Diff(matcher.Expected, actual, matcher.Options)
Expect(map[string]string{
"foo": "bar",
"this": "should be ignored",
}).To(BeComparableTo(map[string]string{
"foo": "bar",
"that": "is an error",
}, diff.IgnoreUnset()))
and return as error message
map[string]string{
... // 1 ignored and 1 identical entries
+ "this": "should be ignored",
}
instead of returning
map[string]string{
... // 1 ignored and 1 identical entries
+ "that": "is an error",
}
I guess the reason it was inverted is maybe because the diff shows the fields missing from the actual object but present in the expected object with a + (instead of a -), maybe that could be documented in the function description or in the error message instead of the second call being inverted ?
Is this an issue that should be corrected (in which case I could open a PR) or should I make my own CustomMatcher ?
hey @antonincms thanks for this. yes this issue should be corrected. can you open a PR? we should swap the elements in cmp.Diff. I don't expect the +/- to confuse folks much.
I am using BeComparableTo with IgnoreUnset, a helper function from k8s.io/apimachinery that "ignores fields that are unset on the right hand side of a comparison". This option is very helpful to check that a struct is a derivative of another struct.
When using it, the "Match" function behave correctly, so if everything is as it should be it does not error, but if something is not, the failure message show differences that should be ignored by the option.
I think the issue is that the option I use "ignores fields that are unset on the right hand side of a comparison", and that (note the difference in order between actual and matcher.Expected):
cmp.Equal(actual, matcher.Expected, matcher.Options...)
cmp.Diff(matcher.Expected, actual, matcher.Options)
Here is an example :
and return as error message
instead of returning
I guess the reason it was inverted is maybe because the diff shows the fields missing from the actual object but present in the expected object with a + (instead of a -), maybe that could be documented in the function description or in the error message instead of the second call being inverted ?
Is this an issue that should be corrected (in which case I could open a PR) or should I make my own CustomMatcher ?