Closed coxley closed 7 months ago
This sounds like a good idea, but I think you likely want to propose it to the https://github.com/grpc/grpc-go/issues board, as they’re the people who maintain the google.golang.org/grpc
packages.
@puellanivis: This would require generated code, though, no?
I'm happy to move/cross-post where necessary. I just want to make sure that throwing it over there makes sense. :)
The protoc-gen-go-grpc
gRPC code generator is part of gRPC-Go:
https://github.com/grpc/grpc-go/tree/master/cmd/protoc-gen-go-grpc
Bah, sorry for the noise! I saw protoc-gen-go here and my brain auto-completed "grpc".
Moving!
Summary
My teams and I find ourselves writing test scaffolding like this a lot:
We can create our own test helpers, but it's pretty unwieldy / ugly to use even with generics because of the generated factory functions:
pb.RegisterServer
,pb.NewClient
. The signature needs to look something like this to get the appropriate type constraints:I supposed we could make our
protoc-gen-go-grpc-test
, but given thatgoogle.golang.org/grpc/test/bufconn
is a central package it doesn't seem completely out of place to ask for type-specific generation to make this easier.An added benefit would be socializing in-memory testing of gRPC testing as an alternative to using mocks.
I'm not sure what the ideal signature would look like, but for conversation purposes:
Alternatively, this could be avoided if it was easier to use
pb.RegisterServer
andpb.NewClient
in type constraints.