pact-provider-cli

1.0.3 • Public • Published

pact-provider-cli

An abstraction over pact.io's provider tests to hide away any complexities with integrating pact into your pipeline.

To help with getting 'buy in' from other teams and to get them to integrate contract testing it is important to make it as easy as possible. To do this pact-provider-cli is a reusable abstraction over the provider tests to allow data sources to run just 1 command inside their pipeline to run against our consumer contracts in the broker.

This allows us to update the contract versions without having the data source update their code. Instead we can just ask them to update their version of the contract variable passed in.

Global Variables

The pact-provider tool can be used with global variables to define required information. This is the most common use case but can also be used with cli arguements or progamatically as outlined below.

Parameter Required Type Description
PACT_BROKER_URL true string URL of the Pact Broker to retrieve pacts from. Pact.io equivelant is pactBrokerUrl. Required.
PACT_BROKER_CONTRACT_NAME true string Name of the Provider contract. Pact.io equivelant is provider. Required.
PACT_BROKER_TOKEN false string Bearer token for Pact Broker authentication. If using Pactflow, you likely need this option.Pact.io equivelant is pactBrokerToken.
PACT_BROKER_CONTRACT_VERSION false string Contract version. Defaults to ^1 and uses semver. Pact.io equivelant is providerVersion.
PACT_BROKER_APPLICATION_URL true string Running API provider host endpoint. Pact.io equivelant is providerBaseUrl. Required.
PACT_BROKER_APPLICATION_TOKEN false string Bearer token for Provider API authentication.
NODE_ENV false dev/prod Will set contract tags to ["prod"] if prod or ["dev"] if environemnt variable is dev. If you use other tag names please use the cli arguments (or progmatical arguements) to override the global variables.

Usage CLI

Start your application and have it running.

$ npm i -g pact-provider-cli

$ pact-provider --contractName=NameOfContract --pactBrokerUrl=https://MY_BROKER.pact.dius.com.au/ --pactBrokerToken=XXXX --applicationUrl=XXXX

When using the CLI values can be set as global variables but any value passed in on the command line will override this.

Config CLI Options
Parameter Required Type Description
applicationUrl true string Running API provider host endpoint. Pact equivelant is providerBaseUrl. e.g --applicationUrl=XXXX
applicationToken false string Bearer token for Provider API authentication. e.g --applicationToken=XXXX
contractName true string Name of the Provider contract. Overrides global variable PACT_BROKER_CONTRACT_NAME. Pact.io equivelant is provider. e.g --contractName=XXXX
pactBrokerUrl true string URL of the Pact Broker to retrieve pacts from. Required if not using pactUrls. e.g --pactBrokerUrl=XXXX
contractTags false array of strings Array of tags, used to filter pacts from the Broker. Pact.io equivelant is consumerVersionTag. e.g --contractTags={"dev", "prod"}
pactBrokerToken true string Bearer token for Pact Broker authentication. If using Pactflow, you likely need this option. e.g --pactBrokerToken=XXXX
publishVerificationResult false boolean Publish verification result to Broker --pactBrokerToken=true
contractVersion false string Contract version, required to publish verification results to a broker. Pact.io equivelant is providerVersion. e.g --contractVersion=XXXX

Usage Progmatically

Start your application and have it running.

// my-pact-provider-tests.js
const { onRunPactTests } = require("pact-provider-cli");

onRunPactTests();

$ PACT_BROKER_CONTRACT_NAME=NameOfContract PACT_BROKER_TOKEN=XXXX PACT_BROKER_URL=https://MY_BROKER.pact.dius.com.au/ my-pact-provider-tests.js

The global variables are required.

Config Progmatically

A config object can also be passed to the pact tests. Any values passed in here will override environment variables.

// my-pact-provider-tests.js
const { onRunPactTests } = require("pact-provider-cli");

const config = {};

onRunPactTests(config);
Config Progmatically Options
Parameter Required Type Description
applicationUrl true string Running API provider host endpoint. Pact equivelant is providerBaseUrl.
contractName true string Name of the provider contract. Overrides global variable PACT_BROKER_CONTRACT_NAME. Pact equivelant is providerName.
pactBrokerUrl true string URL of the Pact Broker to retrieve pacts from. Required if not using pactUrls.
contractTags false array of strings Array of tags, used to filter pacts from the Broker. Pact equivelant is consumerVersionTag.
pactBrokerToken true string Bearer token for Pact Broker authentication. If using Pactflow, you likely need this option.
publishVerificationResult false boolean Publish verification result to Broker
contractVersion false string Contract version, required to publish verification results to a broker. Pact.io equivelant is providerVersion.

Readme

Keywords

Package Sidebar

Install

npm i pact-provider-cli

Weekly Downloads

3

Version

1.0.3

License

ISC

Unpacked Size

330 kB

Total Files

17

Last publish

Collaborators

  • newskit-api