1.0.3 • Published 4 years ago

pact-provider-cli v1.0.3

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

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.

ParameterRequiredTypeDescription
PACT_BROKER_URLtruestringURL of the Pact Broker to retrieve pacts from. Pact.io equivelant is pactBrokerUrl. Required.
PACT_BROKER_CONTRACT_NAMEtruestringName of the Provider contract. Pact.io equivelant is provider. Required.
PACT_BROKER_TOKENfalsestringBearer token for Pact Broker authentication. If using Pactflow, you likely need this option.Pact.io equivelant is pactBrokerToken.
PACT_BROKER_CONTRACT_VERSIONfalsestringContract version. Defaults to ^1 and uses semver. Pact.io equivelant is providerVersion.
PACT_BROKER_APPLICATION_URLtruestringRunning API provider host endpoint. Pact.io equivelant is providerBaseUrl. Required.
PACT_BROKER_APPLICATION_TOKENfalsestringBearer token for Provider API authentication.
NODE_ENVfalsedev/prodWill 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.

ParameterRequiredTypeDescription
applicationUrltruestringRunning API provider host endpoint. Pact equivelant is providerBaseUrl. e.g --applicationUrl=XXXX
applicationTokenfalsestringBearer token for Provider API authentication. e.g --applicationToken=XXXX
contractNametruestringName of the Provider contract. Overrides global variable PACT_BROKER_CONTRACT_NAME. Pact.io equivelant is provider. e.g --contractName=XXXX
pactBrokerUrltruestringURL of the Pact Broker to retrieve pacts from. Required if not using pactUrls. e.g --pactBrokerUrl=XXXX
contractTagsfalsearray of stringsArray of tags, used to filter pacts from the Broker. Pact.io equivelant is consumerVersionTag. e.g --contractTags={"dev", "prod"}
pactBrokerTokentruestringBearer token for Pact Broker authentication. If using Pactflow, you likely need this option. e.g --pactBrokerToken=XXXX
publishVerificationResultfalsebooleanPublish verification result to Broker --pactBrokerToken=trueboolean
contractVersionfalsestringContract 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);
ParameterRequiredTypeDescription
applicationUrltruestringRunning API provider host endpoint. Pact equivelant is providerBaseUrl.
contractNametruestringName of the provider contract. Overrides global variable PACT_BROKER_CONTRACT_NAME. Pact equivelant is providerName.
pactBrokerUrltruestringURL of the Pact Broker to retrieve pacts from. Required if not using pactUrls.
contractTagsfalsearray of stringsArray of tags, used to filter pacts from the Broker. Pact equivelant is consumerVersionTag.
pactBrokerTokentruestringBearer token for Pact Broker authentication. If using Pactflow, you likely need this option.
publishVerificationResultfalsebooleanPublish verification result to Brokerboolean
contractVersionfalsestringContract version, required to publish verification results to a broker. Pact.io equivelant is providerVersion.
1.0.3

4 years ago

1.0.0-d5e6ee3e9

4 years ago

1.0.0-b7859a290

4 years ago

1.0.2

4 years ago

1.0.0-84ec50dc2

4 years ago

1.0.1

4 years ago

1.0.0-aea01b76d

4 years ago

1.0.0-2df34f7f4

4 years ago

1.0.0

4 years ago

1.0.0-9974f7f25

4 years ago

1.0.0-21244d77e

4 years ago

1.0.0-4c459c608

4 years ago

1.0.0-e95ce1644

4 years ago

1.0.0-3d71b6acd

4 years ago