uber-go / mock

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

Fixed -mockNames not propagating to Recorder and ReturnCall types #127

Closed UnAfraid closed 6 months ago

UnAfraid commented 6 months ago

When you are trying to mock multiple interfaces with the same name and similar methods (for example user.Service Create, post.Service Create, etc..) there is collision in Recorder and ReturnCall types, the -mockNames parameter only changes the main interface name, with the changes proposed in this PR the correct mockName will be applied to the Recorder and ReturnCall types.

Addresses https://github.com/uber-go/mock/issues/117

UnAfraid commented 6 months ago

The idea make sense to me. However, I think there are advantages to keeping *model.Interface plumbed through the calls to GenerateMockRecorderMethod and GenerateMockReturnCall method in case we need the richer representation in future code generation changes. Where we use intf.Name could we just use g.MockName(int.Name) instead?

Sure thing, i'll bring back the parameter *model.Interface.

Could we also add a test for this scenario under mockgen/internal/tests?

Of course