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

Unexported genericBatch prevents GoMock mockgen on Querier interface #84

Closed
kirk-anchor opened this issue May 31, 2023 · 4 comments
Closed

Comments

@kirk-anchor
Copy link

I am trying to use GoMock to generate a mock for the pggen Querier interface. https://github.com/golang/mock

The problem is the struct generated by mockgen cannot have methods with the unexported genericBatch interface as params on the mocked Batch and Scan methods. I tried copying the genericBatch into the mock package and while that makes the methods on the struct work, the struct does not satisfy the Querier interface anymore because the Querier interface expects the methods to have its package's unexported genericBatch interface.

Shouldn't we be able to mock the Querier interface?

@jschaf
Copy link
Owner

jschaf commented May 31, 2023

Does using source mode help? golang/mock#297

@kirk-anchor
Copy link
Author

I am using source mode. It will generate a MockgenericBatch struct that is a mock of the interface but the MockQuerier struct still has Batch and Scan methods with batch genericBatch as an arg, which does not exist. If I manually modify the mock methods to use an arg batch MockgenericBatch then the mock struct won't satisfy the Querier interface because it expects to have Batch and Scan methods with an arg for the unexported batch genericBatch interface.

@kirk-anchor
Copy link
Author

kirk-anchor commented Jun 27, 2023

It would work fine for generating mocks within the same package but I would like the generated mocks to be in a separate package. A couple options would be to make genericBatch exported, i.e. GenericBatch. Or an option to skip generating batch methods. I am using batch queries but only 3 or 4 per batch so disabling batching and using non-batched queries in a transaction would be fine. I can create a pull request if you approve of one of these options.

@kirk-anchor
Copy link
Author

Fixed after batch queries were removed in #93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants