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

New package mode fails to generate proper mock for type alias for interface with type params #217

Open
timofurrer opened this issue Oct 21, 2024 · 1 comment
Assignees

Comments

@timofurrer
Copy link

Actual behavior A clear and concise description of what the bug is.

With the upgrade from v0.4.0 to v0.5.0 we had to manually specify type parameters for mocks that have been generated for type aliases that refer a generic interface with concrete types. Our type alias:

type InboundGRPCToOutboundHTTPStream = grpc.ServerStreamingServer[HttpResponse]

... the grpc.ServerStreamingServer is a generic interface.

The mock produced with v0.5.0 is:

// MockInboundGRPCToOutboundHTTPStream is a mock of InboundGRPCToOutboundHTTPStream interface.
type MockInboundGRPCToOutboundHTTPStream[Res any] struct {
	ctrl     *gomock.Controller
	recorder *MockInboundGRPCToOutboundHTTPStreamMockRecorder[Res]
	isgomock struct{}
}

while for v0.4.0 it was:

// MockInboundGRPCToOutboundHTTPStream is a mock of InboundGRPCToOutboundHTTPStream interface.
type MockInboundGRPCToOutboundHTTPStream struct {
	ctrl     *gomock.Controller
	recorder *MockInboundGRPCToOutboundHTTPStreamMockRecorder
}

The mockgen command used is:

//go:generate mockgen.sh -destination "grpctool.go" -package "mock_rpc" "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool" "InboundGRPCToOutboundHTTPStream,PoolConn,PoolInterface,ServerErrorReporter"

Expected behavior A clear and concise description of what you expected to
happen.

I would expect the mock struct to not need any type parameters and not to be generic.

To Reproduce Steps to reproduce the behavior

Here is the MR where we've done the upgrade: https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/merge_requests/1910

And here the commit that takes care of the breaking changes: https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/merge_requests/1910/diffs?commit_id=e513812928d97762306f8d83a280bbcf681fa94c

Additional Information

  • gomock mode (reflect or source): package?
  • gomock version or git ref: v0.4.0
  • golang version: 1.23

Triage Notes for the Maintainers

@mkumatag
Copy link

we are also facing this issue, surprise to see no text added about this in the release note! whats the solution? is this just safe to just accept these changes and merge or any other solution.?

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

3 participants