Open KrzysztofMadejski opened 5 years ago
@KrzysztofMadejski Here is a simple workaround: add this function to your test file:
func mockMatchedByRegexp(pattern string) {
return mock.MatchedBy(func(path string) bool {
ok, err := regexp.MatchString(pattern, path)
if err != nil {
panic(err)
}
return ok
}
}
EDIT: this is not possible. The mock.MatchedBy
signature returns type argumentsMatcher
which is unfortunately private. This means that it is not currently possible to write such a wrapper. 😢
@KrzysztofMadejski Adding a fully runnable example would be helpful to understand your pain. Here is a template: https://go.dev/play/p/AsRNcxCRdWx
A method that tests string argument if it matches regexp would be helpful.
Currently I'm using
MatchedBy(func)
:But the error (panic btw) is hard to analyze easily:
It would be a lot nicer to have standard error: