Add builtin custom matcher function
Author: ilya-hontarauCreated Feb 18, 2023Updated Mar 17, 2023
Labelstype: feature request
Requested feature Add builtin custom matcher function
Why the feature is needed Currently, we should implement Matcher interface in our own code, and it can be useful to provide the ability to create custom matcher using a function in the lib.
Proposed solution
We can create a constructor function, that accepts fmt.Stringer, a match function and returns a new matcher.
mockMatcher.EXPECT().Matches(gomock.Custom(
gomock.StringerFunc(func() string {
return `expect string contains"test"`
}),
func(i interface{}) bool {
v, ok := i.(string)
if !ok {
return false
}
return strings.Contains(v, "test")
},
)).Return(true)Source: golang/mock