Skip to content

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

Open
@timofurrer

Description

@timofurrer

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions