Open affanshahid opened 2 years ago
I think a better practice here is actually to either put your mocks in their own package. Or, what I personally do is generate them in the test package. This way dependencies on gomock don't leak into production builds. Hope that helps.
@codyoss CMIIW but if interface is unexported mocks won't be able to live in a separate or test package.
Guys, i found an idea how to solve this problem with golang generics!
For example:
type boo struct{}
type fooer interface {
foo() boo
}
And after go:generate
type Mockfooer[T any] struct {
ctrl *gomock.Controller
recorder *MockfooerMockRecorder[T]
}
Well, after that it is possible to put your mock to another package and use it like
mock.NewfooerMock[boo](...)
Is it possible to generate unexported mock types? i.e input:
output:
This way mocks are not exported by the package especially useful when mocking unexported interfaces