I\'d like to test a gRPC service written in Go. The example I\'m using is the Hello World server example from the grpc-go repo.
The protobuf definition is as follows
BTW: as a new contributor, I cannot add to comments. So I am adding a new answer here.
I can confirm that the @Omar approach works for testing a non-streaming gRPC service by testing via the interface without a running service.
However this approach will not work for streams. Since gRPC supports bidirectional streams, it is necessary to fire-up the service and connected to it via the network layer to do testing for streams.
The approach that @joscas takes works for gRPC streams (even though the helloworld sample code does not use streams) using a goroutine to start the service. However, I noticed that on Mac OS X 10.11.6 that it does not release the port used by the service consistently when called from a goroutine (As I understand, the service will block the goroutine and perhaps does not exit cleanly). By firing up a separate process for the service to run in, using 'exec.Command', and killing it before finishing, the port is released consistently.
I uploaded a working test file for a gRPC service using streams to github: https://github.com/mmcc007/go/blob/master/examples/route_guide/server/server_test.go
You can see the tests running on travis: https://travis-ci.org/mmcc007/go
Please let me know if any suggestions on how to improve testing for gRPC services.