Open yunweiguo opened 4 weeks ago
Hi, it's not very clear from your description what you're trying to achieve, since your code snippet supposedly contains client side exception handling, where your client sends the augmented exceptions and not reading the trailers from the api call exception, which is what grpc mock is meant for - mocking external api responses. Unless you want to verify that your sending correct error responses to the external server, but then you need to use the verification methods of grpc mock.
@yunweiguo Here is what I done to mock an error with metadata
val trailers: Metadata = Metadata().apply {
put(Metadata.Key.of("message", Metadata.ASCII_STRING_MARSHALLER), "Additional message")
}
val response: ExceptionResponseActionBuilder = GrpcMock.exception(
Status.UNAUTHENTICATED.asRuntimeException(trailers)
)
GrpcMock.stubFor(
unaryMethod(unaryMethod(TesseractServiceGrpc.getGetQuotePermissionParamMethod())
.willReturn(response)
)
I want to use grpcmock for unit testing, but I've encountered an issue
Here is my code
I put error information in the metadata. And consumer can get the error info.
I want to know how can I mock it?I didn't find a similar usage in the source code of grpcmock. I tried the following code,but it didn't work