Closing the loop with Pact verifications

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.

The problem

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.

The solution

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.

The 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:

NOTE: The Pact Broker is an open source tool that requires you to deploy, administer and host it yourself. If you would prefer a plug-and-play option, we’ve created Pactflow, a fully managed Pact Broker with additional features to simplify teams getting started and scaling with Pact and contract testing. You can get started quickly and for free on our Developer Plan.

Want to know more about how DiUS can help you?

Offices

Melbourne

Level 3, 31 Queen St
Melbourne, Victoria, 3000
Phone: 03 9008 5400

DiUS wishes to acknowledge the Traditional Custodians of the lands on which we work and gather at both our Melbourne and Sydney offices. We pay respect to Elders past, present and emerging and celebrate the diversity of Aboriginal peoples and their ongoing cultures and connections to the lands and waters of Australia.

Subscribe to updates from DiUS

Sign up to receive the latest news, insights and event invites from DiUS straight into your inbox.

© 2024 DiUS®. All rights reserved.

Privacy  |  Terms