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 · 2 comments
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.?

@kszafran
Copy link

kszafran commented Dec 15, 2024

I just ran into a related issue when I tried running mockgen from main.

For a type:

type String = Value[string]

type Value[T any] struct {
	value T
}

v0.5.0 generates mypackage.Value[string], but main generates mypackage.String[string]. The interface method I'm running mockgen for takes mypackage.String.

I suppose this commit changed the behavior: c205527#diff-7afb856f1482ccd4a966519790c1d1adfd0e478ceb074906bf5641cd66026b7fR68

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

4 participants