Hi everyone! I'm not sure if this is the channel t...
# general
b
Hi everyone! I'm not sure if this is the channel to ask this question, but here we go. I'm trying to use providers states to create an entity and then test the contract of a
get
endpoint for that entity. I need to create it first so that the endpoint doesn't return a 404. I have created a provider state setup function in my API, that creates this entity and returns a dictionary with the relevant value for the generator. I am using the docker pact-cli for verifying the provider, and it is calling that endpoint correctly. My issue is that it is not modifying the pact to use the returned id instead of the example specified in the pact. Here's an example of my code:
Copy code
// Consumer in JavaScript
provider
      .given("an existing experiment")
      .uponReceiving("a request to get the experiment")
      .withRequest({
        method: "GET",
        path: fromProviderState("/v3/experiments/${uuid}", `/v3/experiments/${exampleUuid}`),
      })
      .willRespondWith({
        status: 200,
        body: { resource: like({
                 uuid: fromProviderState("${uuid}, exampleUuid)
              })},
      }));
Copy code
# Provider state setup endpoint (Python & FastApi)
@router.get(/pact/setup)
def pact_setup():
    experiment = create_experiment()
    return { "uuid": experiment.uuid }
The setup function is being called by the docker verifier, returning the uuid of the created experiment, but the provider verification is still executing a get request to the
exampleUuid
. Is there anything I'm missing?
Here’s the generated pact from the js code
t
Can you show us the verifier configuration?
Are you sure the setup function is being called?
m
Python doesn’t support verifying V3 pacts, and doesn’t understand the “from provider state” feature
t
ah, of course
b
Oooh. I see. I'm not using pact-python though. Verification is being done through the pact cli docker image. Doesn't that support provider injection? It is calling the setup function correctly (requests are logged properly). It's just not injecting the return value on the contract.
m
Aha!
ok so the answer is yes but no
You actually want https://docs.pact.io/implementation_guides/cli#native-binary-new (the newer verifier). The docker one still uses Ruby. I think we ought to consider getting the new verifier into that image. I’ll raise an issue
Created https://github.com/pact-foundation/pact-ruby-cli/issues/95 to track this issue, but it might get moved about.
b
Well, that explains a lot 😅. I knew it used the ruby version, but I didn't know it doesn't support provider state injection. Thank you for the help and support!
👍 1
m
No worries, it’s confusing. I’m sorry about that
It should be fairly straightforward to swap to the rust version. There might be a docker container for that if it’s your preferred pathway, i’ll take a look. But I do wonder if we should have all of the tools in one place
b
That would be great! I ended up making my verifier in JS, but it would be nice to have a cli ready to use.
👍 1