Created
March 7, 2023 08:04
-
-
Save elchead/ed9b1538b450f318e46ee0b5d1af5bc5 to your computer and use it in GitHub Desktop.
Equality matcher for Gomega
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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