golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.3k stars 610 forks source link

mockgen mocking server instance incorrectly where we get Cannot use type *MockCorpServiceServer as type v0.CorpServiceServer #553

Closed sima-fastly closed 3 years ago

sima-fastly commented 3 years ago

Actual behavior with the latest protoc-gen-go-grpc, to fix the MustEmbedUnimplemented** we need to add v0.UnimplementedCorpServiceServer to the server struct. Once we add that to the server provider, mockgen generates a server interface including mustEmbedUnimplementedCorpServiceServer() method but mocked NewMockCorpServiceServer which returns a MockCorpServiceServer lacks that method. so these 2 types are not matching up and we get a Cannot use type MockCorpServiceServer as type v0.CorpServiceServer

Expected behavior NewMockCorpServiceServer to mock the server correctly based on latest protoc grpc udpates

To Reproduce Steps to reproduce the behavior update protoc-gen-go-grpc to v1.1.0

this issue started happening when google.golang.org/protobuf was updated to 1.26.0 google.golang.org/grpc package was updated to 1.37.0 golang/mock was updated to 1.5.0

gomock mode is reflect go version go1.16.3 darwin/amd64

here is the mockgen cmd I am running mockgen -destination mocks/server_mock.go -package mocks github.com/signalsciences/sigsci/pod/proto/corp/v0 CorpServiceServer

sima-fastly commented 3 years ago

found a work around by adding this flag to protoc cmds protoc --go-grpc_out=require_unimplemented_servers:....