uber-go / mock

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

proposal: Add `OneOf` Matcher #91

Closed abshierjoel closed 9 months ago

abshierjoel commented 9 months ago

This is one potential implementation of proposal #90

This proposal introduces a new Matcher to gomock for matching a parameter against is list of potential values it may have. This should help ease-of-use, when multiple matches are necessary and additionally help navigate around an existing issue with overriding matches.

I would appreciate any and all feedback on this proposal! Thank you!

CLAassistant commented 9 months ago

CLA assistant check
All committers have signed the CLA.

favonia commented 9 months ago

Hi, I believe this PR is largely subsumed by my PR #63, modulo the difference in the interface (the name OneOf versus AnyOf and whether it is taking a slice versus a variable number of arguments). The difference seems minor because one can write AnyOf(choices..) for a slice choices. On the other hand, the AnyOf in #63 can also take matchers such as Len(100), which I believe is more powerful than the OneOf in this PR.

favonia commented 9 months ago

I want to add that this feature has been discussed many times, even before the transfer to Uber. Here were some related discussions (including the one after the transfer):

I hope that the PR #63 (or at least this PR) can be merged soon. 😀

r-hang commented 9 months ago

As an update here, I've already approved and plan to merge https://github.com/uber-go/mock/pull/63#pullrequestreview-1631937634 to address this issue.

r-hang commented 9 months ago

@abshierjoel, given https://github.com/uber-go/mock/pull/63 is it okay if we close this issue?

r-hang commented 9 months ago

Closing now that https://github.com/uber-go/mock/pull/63 has landed.

abshierjoel commented 9 months ago

@r-hang apologies for the slow response on this. Thanks for feedback @Tulzke and @favonia -- I really appreciate it! Glad we'll got something better with #63!