This is an example of a NodeJS "Product" API Provider that uses Dredd, Pact, PactFlow and GitHub Actions to generate and publish Pact provider contracts.
It performs pre-deployment cross-compatability checks to ensure that it is compatible with specified consumers using the Bi-Directional contract capability of PactFlow.
See the full PactFlow Bi-Directional Workshop for which this can be substituted in as the "provider".
It:
What is uploaded to PactFlow is an OpenAPI specification that represents what you actually tested with Dredd, to give us confidence it is compatible with a Pact consumer.
In the following diagram, you can see how the provider testing process works.
When we call "can-i-deploy" the cross-contract validation process kicks off on PactFlow, to ensure any consumer consumes a valid subset of the OAS for the provider.
The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.
When you run the CI pipeline (see below for doing this), the pipeline should perform the following activities (simplified):
can-i-deploy
(ie. has the cross-contract validation has been successfully performed)This project is currently compatible with the following consumers(s):
See Environment variables on how to set these up
Software:
To be able to run some of the commands locally, you will need to export the following environment variables into your shell:
PACT_BROKER_TOKEN
: a valid API token for PactFlowPACT_BROKER_BASE_URL
: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.ioSet PACT_PROVIDER
to one of the following
PACT_PROVIDER=pactflow-example-bi-directional-provider-dredd
: Dredd - (https://github.com/pactflow/example-bi-directional-provider-dredd)PACT_PROVIDER=pactflow-example-bi-directional-provider-postman
: Postman - (https://github.com/pactflow/example-bi-directional-provider-postman)PACT_PROVIDER=pactflow-example-bi-directional-provider-restassured
: Rest Assured - (https://github.com/pactflow/example-bi-directional-provider-restassured)make test
- run the tests locallymake fake_ci
- run the CI process, but locallyThe makefile is configured to run on Unix based systems such as you would find in most common CI/CD pipelines.
They can be run locally on Unix/Mac, or on Windows via WSL2.
You can still try this example locally on Windows using powershell and running commands manually.
Reach out via a GitHub Issue, or reach us over in the Pact foundation Slack