How we reached Pact Nirvana — Diamond Level
4 min read
·
Oct 25, 2023
At Go City, contract testing with Pact is part of each teams' definition of done, ensuring that we’re not breaking our REST APIs between our mobile apps, websites and suite of microservices.
We’ve just reached ‘Pact Nirvana — Diamond Level’, a level I personally have never reached on a production system, despite writing Pact contract tests for 6+ years.
What is ‘Pact Nirvana — Diamond Level’?
Reaching diamond level means you have automated every stage of Pact into your CI/CD workflow for PRs and release branches, helping to give you confidence that your changes can be safely released to production.
Flow (Simplified):
- PRs and release branches (
main) publish consumer contracts to the broker. - Pact Webhooks trigger a build of the provider in your CI/CD tool if a consumer contract is new/modified and therefore requires verifying.
- Provider tests then run for the contract that needs verification and publishes the verification results back to the broker.
- Consumers and Providers both check with
can-i-deploybefore merging to your release branch or releasing to an environment. - Consumers and Providers
recording-deploymentwhen the code has been promoted to an environment.
Using the retry-while-unknown and retry-interval properties gives the provider tests time to run and report the verification results.
We even have GitHub status checks for Pact verifications on all our PRs and added the can-i-deploy badges to each repo's README.md.
How we did our provider webhook verification
To apply quickly across our suite of microservices, instead of updating every single CI/CD workflow with a “Run provider tests” job, we created a new repo called pact-contract-verification-webhook-receiver which is triggered by a Pact webhook that includes all the information about the consumer and provider. It in turn checks out the required provider repo and branch/version, runs just the provider tests for the changed consumer contract and publishes the verification results to the Pact broker.
What’s next?
We still have plenty of work to do with Pact. At the time of writing, we have only experimented with messaging pacts (We use Kafka!).
We also want to look into the new plugins, bidirectional contracts, WIP and pending pacts to determine whether they will help improve the way we test our services at Go City.