First, some background!
Imagine — you’re on a team writing an app that uses three different HTTP APIs, and you’ve decided to use consumer contracts to test your integrations. You’ve chosen to use Pact (an excellent choice, may I say), and you love that it allows you to run fast, standalone tests in each project, while giving you confidence that your applications will work together correctly in production. #winningatlife
To enable you to easily share your contracts (called “pacts”) between teams, you’re using a service that has been written specifically for this purpose, called a Pact Broker. It serves as a middleman between your consumer and provider projects, allowing you to publish pacts that were created by the consumer CI builds, and making them available for the provider builds to verify.
Webhooks in the pact broker kick off the provider verification builds every time a pact changes, so your API teams know whether or not they’re compatible with your latest consumer code. But there the process stops. They never call. They never write. You’ve tried facestalking them, but they’ve had all their pics locked down since that awkward incident at the company party two years ago. They’re probably not publishing photos of their CI results anyway.
As a member of the consumer development team
I want to know whether the provider verification builds passed or failed
So that I know whether or not I can safely deploy my code.
Yes, it’s time to upgrade all the Pact Things!
We’ve been busy here at DiUS adding some new features to the Pact Broker and Pact implementations to enable the outcome of those provider verification builds (Did it pass or fail? Which version of the provider verified the pact?) to be automatically published back to the broker. Once you’ve upgraded your Pact Broker, your index page will have a killer new feature.
The rightmost column will contain the latest verification result for each pact. Green means the latest pact was verified successfully. Red means that verification failed. Yellow means that the pact content has changed since the last successful verification, so its status is unknown.
The Pact Broker is smart enough to work out whether the pact content has changed or not, so if a pact is published with the same content as a previous one, it will inherit the same verification results — we call this being “pre-verified”. To enable the verification results to be published, you’ll need to switch on the “publish verification results” flag in your Pact verification configuration, and tell it what version your provider is. See your Pact library documentation for the relevant syntax in each language.
Displaying the results in the broker is great, but what you you really need is to get those results back to your consumer CI, so you know that you can deploy. This is where the Pact Broker CLI comes in handy.
pact-broker can-i-deploy tool will let you check the verification results, and act as a gateway for your deployments. If you’re deploying to a test environment for further integration tests, you can be confident that they’ll pass. If you’re deploying straight to production, there’s no longer any need to wait by your phone for that message from the provider team, wondering if you’ll look desperate if you send them another message before they’ve replied…
Now, while you’re updating your libraries, hop into your README files, and add some some shiny new verification badges. You’ll find the markdown to add these when you view your pact in the Pact Broker.
The new Pact tools close the verification loop by providing an API for the provider to publish the verification results, and for the consumer to retrieve the verification results. Before verifications, you had to create complex scripts to determine if your consumer was safe to release or worse — trust that the consumer team would deploy when the time was right. Now, with a single API, you have safeguards on both sides of the contract that supports a simple and streamlined deployment process.
So what are you waiting for? Go upgrade all the things, or better yet, grab yourself a free hosted one at pact.dius.com.au so you’ll always have the latest features.
For technical docs, see the following links: