Closed christophsturm closed 11 months ago
Hi @christophsturm , this was done in a similar manner as is done in wiremock.
I could expose methods for returning the int count
, but I wouldn't want to expose CapturedRequest
structure as it has a lot of info and it would require a lot of redundant definitions in your assertion (ie. all the incoming headers)
the problem with the current approach is that when just one of my matchers is not met the assertion fails and i don't know what is wrong with the request.
for example a verify call like this:
.withHeader("authorization", GRPCUtils.isJwtToken)
.withRequest(r -> ..., times(1));
it just tells me that it was not called like this 1 times, but to track down the error i would like to see the actual request.
the workaround that I am currently using if I really want to assert on the request is this:
// get the grpc requests for manual asserting:
LinkedList<...> requests = new LinkedList<>();
grpcMock.verifyThat(calledMethod(...).withRequest(requests::add)
.withHeader("authorization", GRPCUtils.isJwtToken).build(),
times(1));
assertThat(requests).hasSize(1);
assertThat(requests.get(0).getBlah()).isEqualTo("...");
but I think it would be best if I could just get a list of requests with headers for a called method.
@christophsturm fair enough, that sounds like a valid use case. I can introduce a method to returns the list of CapturedRequest
.
perfect. why does it return a list of captured requests, and then each captured request again contains a list of requests? do I need to flat map them to get all the request?
perfect. why does it return a list of captured requests, and then each captured request again contains a list of requests? do I need to flat map them to get all the request?
CapturedRequest
encapsulates all gRPC supported method types. That includes client streaming and bidi streaming methods, which can contain multiple requests in the same call.
I would like to verify my grpc requests with my assertion lib instead of using verify, something like
mainly to get better error messages and because I think asserting should be left to assertion libs.