Closed savbiz closed 1 year ago
Hi @savbiz, I haven't used these libraries at any capacity, so I can't tell for sure. But from what you've described it seems that your grpcmock instance is started on one thread and stubs are configured on a different one and in order to use the static methods it has to be on the same one as it depends on ThreadLocals. You can try to register the stub methods directly on the grpcmock instance that you're injecting in constructor instead.
Thanks for the pointer, @Fadelis!
Registering the stub methods directly on my instance did the trick. :)
Example here:
val expectedRequest = GetXRequest.newBuilder()
.setXName("name")
.setXKey("x)
.build()
val expectedResponse = GetXResponse.newBuilder()
.setX("success")
.build()
grpcMock.register(
unaryMethod(XGrpcServiceGrpcKt.getXForUserMethod)
.withRequest(expectedRequest)
.willReturn(expectedResponse),
)
val requestPattern =
RequestPatternBuilderImpl(XGrpcServiceGrpcKt.getXForUserMethod)
.withStatusOk()
.withRequest(expectedRequest)
.withHeader("X", "value)
.build()
grpcMock.verifyThat(
requestPattern,
once(),
)
Does the library support Kotest and Grpc services implemented in Kotlin?
I keep getting
UNIMPLEMENTED
even though I can see in the logs that the requests hit GrpcMock. I suspect that thestubFor
doesn't really work properly with those 2 Kotlin libraries.