Fadelis / grpcmock

A gRPC Java testing tool to easily mock endpoints of gRPC services for IT or Unit testing
http://grpcmock.org
Apache License 2.0
144 stars 13 forks source link

Enhancement: Add 'willProxyTo' to all communication types #18

Closed RomanKhachko closed 2 years ago

RomanKhachko commented 2 years ago

Currently, the interface StreamRequestProxyResponseBuilderStep is implemented by classes supporting streaming from the client-side (client and bidi streams). However, it would be extremely beneficial to add this functionality for other communication types (server stream and unary).

We use this library not for testing purposes, but as an embedded mock server for our local development experience. Method 'willProxyTo' allows providing a custom dynamic behavior. Therefore, besides predefined responses, we could provide implementations handling request values in runtime.

Fadelis commented 2 years ago

Hi @RomanKhachko , this is already available for both unary and server streaming requests. There's a method .willProxyTo((request, responseObserver) -> ...), where you control the whole flow, and also .willReturn(request -> ...) where you can respond based on the request and will complete the call that call for you after this function completes. You can see more examples here and here

RomanKhachko commented 2 years ago

Amazing! Thanks a lot for the clarification! It's exactly what is needed. We can remove the request then.