uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.82k stars 104 forks source link

Add a matcher for checking a string parameter against regex #113

Closed merrett010 closed 8 months ago

merrett010 commented 8 months ago

Requested feature

I've found times where it would be useful to check that string parameters being passed to a function match against some regex.

A specific example could be an SQS message body string containing a UUID that was generated during execution and I won't know what it is ahead of time, but I want to check against the majority of the body being passed to the mock, even though I don't care exactly what the UUID is.

sqsClient.
  EXPECT().
  SendMessage(gomock.AssignableToTypeOf(context.Background()), gomock.Regex(expectedMessageBodyRegex))

Why the feature is needed

I've created a custom matcher for my use cases, but thought I'd offer it up here with an issue and PR in case you could see it being useful.

(Optional) Proposed solution

PR to follow very shortly, see below