Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mock_names flag does not change naming of ...Call struct in typed mocks #117

Open
ojcm opened this issue Nov 9, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@ojcm
Copy link

ojcm commented Nov 9, 2023

Actual behavior
Using -mock_names option does not alter the name of ...Call structs.

e.g. mockgen -typed=true -mock_names=Writer=OtherWriter io Writer generates

// WriterWriteCall wrap *gomock.Call
type WriterWriteCall struct {
	*gomock.Call
}

This causes problems if using -mock_names to avoid clashes between mocks for interfaces with the same name (e.g. if I have my own Writer interface and also want to mock io.Writer in the same package) since there will be multiple structs with the same type name in the same package.

Expected behavior
I expect using -mock_names option to change the name of ...Call structs.

e.g. mockgen -typed=true -mock_names=Writer=OtherWriter io Writer generates

// OtherWriterWriteCall wrap *gomock.Call
type OtherWriterWriteCall struct {
	*gomock.Call
}

To Reproduce

Run mockgen -typed=true -mock_names=Writer=OtherWriter io Writer

Additional Information

  • gomock mode (reflect or source): both
  • gomock version or git ref: v0.3.0
  • golang version: 1.21.3

Triage Notes for the Maintainers

@sywhang sywhang added the bug Something isn't working label Nov 21, 2023
r-hang pushed a commit that referenced this issue Dec 19, 2023
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 #117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants