Description
Actual behavior
I'm trying to generate a mock for a type that is a type alias for a generic interface. This is new functionality in gRPC (grpc/grpc-go#7030), available in protoc-gen-go-grpc v1.5.0.
Before v1.5.0 the type looks like this (works fine with source and reflect modes):
type GitLabFlux_ReconcileProjectsClient interface {
Recv() (*ReconcileProjectsResponse, error)
grpc.ClientStream
}
v1.5.1 generates the following:
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type GitLabFlux_ReconcileProjectsClient = grpc.ServerStreamingClient[ReconcileProjectsResponse]
gRPC type looks like this:
// ServerStreamingClient represents the client side of a server-streaming (one
// request, many responses) RPC. It is generic over the type of the response
// message. It is used in generated code.
type ServerStreamingClient[Res any] interface {
Recv() (*Res, error)
ClientStream
}
mockgen just ignores the type as if it's not in the file.
I've also tried to add a replacement type like this:
// Doesn't work
type gitLabFlux_ReconcileProjectsClient interface {
rpc.GitLabFlux_ReconcileProjectsClient
}
The above produces an error (I couldn't fix it with -aux_files
):
2024/07/30 19:21:56 Loading input failed: doc.go:16:2: unknown embedded interface gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/module/flux/rpc.GitLabFlux_ReconcileProjectsClient
If I use the gRPC's interface explicitly, it works fine:
// Works fine. This is my own type, not the generated one.
type gitLabFlux_ReconcileProjectsClient interface {
grpc.ServerStreamingClient[rpc.ReconcileProjectsResponse]
}
Expected behavior
I expect the generated alias GitLabFlux_ReconcileProjectsClient
interface to generate a mock. I generate mocks for all gRPC-generated interfaces but this one (and similar ones) is skipped so I have to work this around, which is annoying.
To Reproduce
Use a type alias and try to generate a mock for it.
Additional Information
- gomock mode (reflect or source): source
- gomock version or git ref: v0.4.0
- golang version: v1.22.5
Triage Notes for the Maintainers