onsi / gomega

Ginkgo's Preferred Matcher Library
http://onsi.github.io/gomega/
MIT License
2.16k stars 282 forks source link

BeComparableTo behave differently between Match and FailureMessage which breaks with some options #719

Closed antonincms closed 8 months ago

antonincms commented 8 months ago

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

Here is an example :

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 ?

onsi commented 8 months ago

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.