Skip to content

Commit

Permalink
Inverted arguments order of FailureMessage of BeComparableToMatcher
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antonincms authored and onsi committed Jan 18, 2024
1 parent ba8bba2 commit e0dd999
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions matchers/be_comparable_to_matcher.go
Expand Up @@ -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)
}

0 comments on commit e0dd999

Please sign in to comment.