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

Generic Streams from protoc-gen-go-grpc are not detected by mock tools #7594

Closed
cesnietor opened this issue Sep 6, 2024 · 4 comments
Closed
Assignees
Labels
Area: Codegen Includes anything related to protoc-gen-go-grpc. Type: Bug

Comments

@cesnietor
Copy link

What version of gRPC are you using?

protobuf 28.0
protoc-gen-go-grpc v1.5.1

What version of Go are you using (go version)?

go version go1.22.5 darwin/arm64

What operating system (Linux, Windows, …) and version?

macOS

What did you do?

We are using mockery for unittests for our handlers.
Mockery needs the interface to know what to mock and then create the corresponding mocking files that we can then use in unittests to make testing a bit easier. e.g.

with-expecter: True
packages:
  github.com/.../protos:
    interfaces:
      ServiceRpcs_BlaServer

New generic types introduced in protoc-gen-go-grpc v1.5.0 has a change tha no longer defines the interfaces but just assigns the type to a generic interface. Although this still works in the implementation of the handler, it no longer works for tools like mockery to detect it. I already tried, without success, to see if the new type could be used for unittests.

Fortunately a flag was introduced to disable this feature which I appreciate a lot, but just raising our use case so that we can discuss and see if we could bring this old implementation back.

What did you expect to see?

Keep defining Streaming interfaces instead of generic ones.

What did you see instead?

New server uses generic types which is no longer compatible with mock tool.

@aranjans aranjans self-assigned this Sep 10, 2024
@arjan-bal
Copy link
Contributor

arjan-bal commented Sep 10, 2024

Hi @cesnietor, we intend to keep the code generation using generics as it simplifies the code generation process and the generated code. Maybe you could ask mockery devs to support generic interfaces?
I found this issue that may be similar to the one you're seeing: vektra/mockery#787

We do plan to remove the flag for the old behaviour in an upcoming release of protoc-gen-go-grpc.

@arjan-bal arjan-bal assigned cesnietor and unassigned aranjans Sep 10, 2024
@arjan-bal
Copy link
Contributor

Closing this issue, feel free to re-open if there are further questions.

@purnesh42H purnesh42H added the Area: Codegen Includes anything related to protoc-gen-go-grpc. label Sep 12, 2024
@cesnietor
Copy link
Author

Thanks, will raise with mockery team.

@dfawley
Copy link
Member

dfawley commented Sep 18, 2024

Just wanted to add: from personal experience, mocking RPC handlers can be problematic, as it assumes the behavior of gRPC, which might not match your expectations in all cases. I would highly recommend changing your testing approach to use a fake server implementation (or client?) with a real gRPC channel instead. Or refactor and unit test smaller pieces if that's the style you prefer. Let us know if you need any help with that, or if you need a better explanation of the approach or justification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Codegen Includes anything related to protoc-gen-go-grpc. Type: Bug
Projects
None yet
Development

No branches or pull requests

5 participants