Hi! I am trying to implement schema-based provider...
# pactflow
m
Hi! I am trying to implement schema-based provider contract testing and I am following this example: https://github.com/pactflow/pactflow-jsonschema-example When downloading the contracts, the example specifies an hardcoded consumer (see this line in the Makefile). However wouldn't I ideally try to download all the latest contracts I find for my provider? I could not find the right API reference to do that. Could someone advise? Thanks so much!
m
Ideally yes. You could use the same API pact verification uses here to dynamically discover them: https://smartbear.portal.swaggerhub.com/pactflow/default/pactflow_saas_api#/verifiable-pacts/post_pacts_provider__providerName__for-verification
👍 1
May I ask, why are you using this flow? What's your use case?
m
We are building an "event schema interface" where nor the consumer nor the providers own the schema, but they use the schema of the interface as contracts. So I chose schema-based testing because consumer and provieders should not be coupled. There are also many producers for the same event schema
👍 1
m
Keen to see what you come up with! Please share your findings 🙏
m
Thanks Matt! I have used that endpoint to fetch the list of integrations, from then extracted the URL of the specific integration. When I fetch data with that, I get a body that does not contain the key
schema
. Each interaction has the properties
contents
and
matchingRules
, which I can probably leverage to achieve what I need. But how come does the example expects a
schema
property that I do not get?
m
Is it fetching pact files or your schema file?
Mind showing me the request/response?
m
It is fetching pact files I believe
🤔 1
I have sent you the request and response in DMs
I was thinking to use the
content
of the PACT to verify against the golden schema, but I am not sure whether that's a true verification?
m
So when you pact is published (https://github.com/pactflow/pactflow-jsonschema-example/blob/master/Makefile#L49) it uses the branch name as the tag. That’s a bit out dated now, you should use the
--branch
flag instead (see also https://docs.pact.io/getting_started/conceptual_overview#branches--environments). How are you calling the
/for-verification
endpoint? When you call that, it should accept a number of consumer selectors - these configure how you automatically discover contracts in the broker. My suspicion is finding pacts unrelated to what you need (either for the wrong provider, or it’s not matching a branch or something) More generally, you should understand the pact workflow (even if you don’t use the Pact SDKs, because the broker enforces and provides the generalised workflow)
m
I am setting the provider in the URL (
/pacts/provider/${PROVIDER_NAME}/for-verification
) and I get back only the right pacts I expect. I have not configured consumer selectors at this moment in time but it is fine for testing - we have only one consumer and a few pact published. I was planning to specifically select pacts by passing a body looking like this:
Copy code
{
    "consumerVersionSelectors": [{ "branch": "main"}],
    "includePendingStatus": true,
}
As the API does not return me a
schema
I am actually using the
content
object of the interaction to compare it against the my golden schema. I am not sure this is the best course of action but that's what I managed to get working for now. I also managed to successfully publish the results via the
pb:publish-verification-results
link, however I haven't figured yet how report on each specific interaction rather than failing them all
[...] however I haven't figured yet how report on each specific interaction rather than failing them all
Sorted that! I am sending a PUT request to
pb:provider/branches/${branch}/versions/${version}
.
👍 1