From e0dd999861372e3b7838b6719258eee5fd16276a Mon Sep 17 00:00:00 2001 From: Antonin <9219052+antonincms@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:03:09 +0100 Subject: [PATCH] Inverted arguments order of FailureMessage of BeComparableToMatcher BeComparableTo behaved differently between Match and FailureMessage which made asymmetric go-cmp Options (e.g. https://pkg.go.dev/k8s.io/apimachinery/pkg/util/diff#IgnoreUnset) print a nonsensical error message. Fixed this issue by inverting order or comparison, and improved a bit messages. --- matchers/be_comparable_to_matcher.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matchers/be_comparable_to_matcher.go b/matchers/be_comparable_to_matcher.go index 8ab4bb919..4e3897858 100644 --- a/matchers/be_comparable_to_matcher.go +++ b/matchers/be_comparable_to_matcher.go @@ -41,9 +41,9 @@ func (matcher *BeComparableToMatcher) Match(actual interface{}) (success bool, m } func (matcher *BeComparableToMatcher) FailureMessage(actual interface{}) (message string) { - return cmp.Diff(matcher.Expected, actual, matcher.Options) + return fmt.Sprint("Expected object to be comparable, diff: ", cmp.Diff(actual, matcher.Expected, matcher.Options...)) } func (matcher *BeComparableToMatcher) NegatedFailureMessage(actual interface{}) (message string) { - return format.Message(actual, "not to equal", matcher.Expected) + return format.Message(actual, "not to be comparable to", matcher.Expected) }