Hello, I'm trying to implement gRPC/protobuf tests...
# protobufs
e
Hello, I'm trying to implement gRPC/protobuf tests for my application and I'm wondering if the gRPC/protobuf plugin has something like the
valueFromProviderState
that the REST API has? this is in case I would like to inject something like entity ID of an entity created during the state setup into the gRPC call
m
hmm I recall something like this being asked recently, but I don’t recall the answer. I think it’s no, however
e
is this by design or there never was any demand for it?
@Matt (pactflow.io / pact-js / pact-go) is there a feature request for this somewhere? (if not, where/how can I propose this?)
is there a possible workaround for this? (i.e. creating entities as part of the state setup and somehow planting their IDs magically into the request Pact makes) I'm using a SpringBoot + JUnit5 + PactJVM + Pact protobuf plugin 0.4.0 stack if that matters at all
m
sorry, I missed your other note
I’m not sure where the capability would live. @rholshausen would this be a capability we need to add into the Plugin framework and then expose to the plugins / SDKs themselves?
r
The gRPC/protobuf plugin does support that (in theory), but I have never tested it
However, I think there is an implementation gap where the values from the provider states are not being passed in to the plugin
Can you raise an GitHub issue for this? It looks like it will work for basic Protobufs, but the gRPC mock server is missing the data from the provider states, so will not be able to inject the values.
πŸ‘ 1
m
r
Yes
πŸ‘ 1
m
done
thankyou 1
e
will this include
headerFromProviderState
as well? this is what I'm doing for authentication at the moment:
Copy code
@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactTestTemplate(PactVerificationContext context, RequestData requestData) {
    if (pactGrpcGlobalContext.getToken() != null) {
        requestData.getMetadata().put("Authorization", pactGrpcGlobalContext.getToken());
    }
    context.verifyInteraction();
}
which isn't ideal because I'm forced to store the token that is generated at state setup (unique to the entity I create for the test) in a "global" bean which means I can't parallelize the test execution properly
Hi @rholshausen, I see that you pushed a commit related to this issue that Matt created, I just wanted to make sure that the solution will include a behaviour similar to
headerFromProviderState
- to have parity with the REST stack (where it makes sense to have it at least)
r
It will support injecting values into gRPC metadata, not HTTP headers. But that will come second. I will release support for injecting values into the Protobuf messages first.
e
do you mean a separate PR or a separate release? I guess we are setting the "Authorization" on the
RequestData.metadata
so I guess that will work for us? - I'm not too sure how that works internally TBH
thanks for taking this on so quickly! πŸ™‚
r
No problem. Yeah, RequestData.metadata is the gRPC metadata. So all good.
do you mean a separate PR or a separate release?
More like a separate PR, but I won't create an actual PR as there is really nobody to review it. I'll first create example projects for the bodies, make the changes, and then get those example tests to pass. We can release at this point, but as you need it for the metadata I'll then repeat the process.
thankyou 1
First bit is working
πŸ™Œ 2
e
@rholshausen any idea when this (protobuf plugin 0.5.0) will be available?
r
I sure do
πŸŽ‰
πŸ™Œ 1
e
I'v tried protobuf plugin 0.5.0 + PactJVM 4.5.12 and seems to work as expected πŸŽ‰
@rholshausen @Matt (pactflow.io / pact-js / pact-go) thank you for taking on this enhancement so quickly!
r
You're welcome. Beats doing real work.