Skip to content

Instantly share code, notes, and snippets.

@elchead
Created March 7, 2023 08:04
Show Gist options
  • Save elchead/ed9b1538b450f318e46ee0b5d1af5bc5 to your computer and use it in GitHub Desktop.
Save elchead/ed9b1538b450f318e46ee0b5d1af5bc5 to your computer and use it in GitHub Desktop.
Equality matcher for Gomega
// source: https://github.com/golang/mock/issues/616#issuecomment-1049275800
// see the differences between expected and wanted object in a nice format
type eqMatcher struct {
want interface{}
}
func EqMatcher(want interface{}) eqMatcher {
return eqMatcher{
want: want,
}
}
func (eq eqMatcher) Matches(got interface{}) bool {
return gomock.Eq(eq.want).Matches(got)
}
func (eq eqMatcher) Got(got interface{}) string {
return fmt.Sprintf("%v (%T)\nDiff (-got +want):\n%s", got, got, strings.TrimSpace(cmp.Diff(got, eq.want)))
}
func (eq eqMatcher) String() string {
return fmt.Sprintf("%v (%T)\n", eq.want, eq.want)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment