<commit_before># Pact Go

Golang version of [Pact](http://pact.io). Enables consumer driven contract testing, providing a mock service and
DSL for the consumer project, and interaction playback and verification for the service Provider project.

[![wercker status](https://app.wercker.com/status/fad2d928716c629e641cae515ac58547/s/master "wercker status")](https://app.wercker.com/project/bykey/fad2d928716c629e641cae515ac58547)
[![Coverage Status](https://coveralls.io/repos/github/pact-foundation/pact-go/badge.svg?branch=HEAD)](https://coveralls.io/github/pact-foundation/pact-go?branch=HEAD)
[![Go Report Card](https://goreportcard.com/badge/github.com/pact-foundation/pact-go)](https://goreportcard.com/report/github.com/pact-foundation/pact-go)
[![GoDoc](https://godoc.org/github.com/pact-foundation/pact-go?status.svg)](https://godoc.org/github.com/pact-foundation/pact-go)

## Introduction

From the [Pact website](http://docs.pact.io/):

>The Pact family of frameworks provide support for [Consumer Driven Contracts](http://martinfowler.com/articles/consumerDrivenContracts.html) testing.

>A Contract is a collection of agreements between a client (Consumer) and an API (Provider) that describes the interactions that can take place between them.

>Consumer Driven Contracts is a pattern that drives the development of the Provider from its Consumers point of view.

>Pact is a testing tool that guarantees those Contracts are satisfied.

Read [Getting started with Pact](http://dius.com.au/2016/02/03/microservices-pact/) for more information on
how to get going.

Pact Go implements [Pact Specification v2](https://github.com/pact-foundation/pact-specification/tree/version-2),
including [flexible matching](http://docs.pact.io/documentation/matching.html).

[![asciicast](https://asciinema.org/a/121445.png)](https://asciinema.org/a/121445)

## Table of Contents

<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:1 -->

1. [Table of Contents](#table-of-contents)
2. [Installation](#installation)
3. [Running](#running)
	1. [Consumer](#consumer)
		1. [Matching (Consumer Tests)](#matching-consumer-tests)
	2. [Provider](#provider)
		1. [Provider States](#provider-states)
	3. [Publishing Pacts to a Broker and Tagging Pacts](#publishing-pacts-to-a-broker-and-tagging-pacts)
		1. [Publishing from Go code](#publishing-from-go-code)
		2. [Publishing from the CLI](#publishing-from-the-cli)
        4. [Publishing Verification Results to a Pact Broker](#publishing-verification-results-to-a-pact-broker)
	5. [Using the Pact Broker with Basic authentication](#using-the-pact-broker-with-basic-authentication)
	6. [Output Logging](#output-logging)
4. [Examples](#examples)
5. [Contact](#contact)
6. [Documentation](#documentation)
7. [Roadmap](#roadmap)
8. [Contributing](#contributing)

<!-- /TOC -->

## Installation

* Download a [release](https://github.com/pact-foundation/pact-go/releases) for your OS.
* Unzip the package into a known location, and add to the `PATH`.
* Run `pact-go` to see what options are available.

*NOTE*: Don't despair! We are [working](https://github.com/pact-foundation/pact-go/tree/feature/native)
on a pure Go implementation that won't require this install step - please be
patient or help us implement the [roadmap](https://github.com/pact-foundation/pact-go/wiki/Native-implementation-roadmap).

## Running

Due to some design constraints, Pact Go runs a two-step process:

1. Run `pact-go daemon` in a separate process/shell. The Consumer and Provider
DSLs communicate over a local (RPC) connection, and is transparent to clients.
1. Create your Pact Consumer/Provider Tests. It defaults to run on port `6666`.

*NOTE: The daemon is completely thread safe and it is normal to leave the daemon
running for long periods (e.g. on a CI server).*

### Consumer
1. Start the daemon with `./pact-go daemon`.
1. `cd <pact-go>/examples`.
1. `go run -v consumer.go`.

Here is a simple example (`consumer_test.go`) you can run with `go test -v .`:

```go
package somepackage

import (
	"fmt"
	"github.com/pact-foundation/pact-go/dsl"
	"net/http"<commit_msg>chore(docs): improve installation instructions<commit_after># Pact Go

Golang version of [Pact](http://pact.io). Enables consumer driven contract testing, providing a mock service and
DSL for the consumer project, and interaction playback and verification for the service Provider project.

[![wercker status](https://app.wercker.com/status/fad2d928716c629e641cae515ac58547/s/master "wercker status")](https://app.wercker.com/project/bykey/fad2d928716c629e641cae515ac58547)
[![Coverage Status](https://coveralls.io/repos/github/pact-foundation/pact-go/badge.svg?branch=HEAD)](https://coveralls.io/github/pact-foundation/pact-go?branch=HEAD)
[![Go Report Card](https://goreportcard.com/badge/github.com/pact-foundation/pact-go)](https://goreportcard.com/report/github.com/pact-foundation/pact-go)
[![GoDoc](https://godoc.org/github.com/pact-foundation/pact-go?status.svg)](https://godoc.org/github.com/pact-foundation/pact-go)

## Introduction

From the [Pact website](http://docs.pact.io/):

>The Pact family of frameworks provide support for [Consumer Driven Contracts](http://martinfowler.com/articles/consumerDrivenContracts.html) testing.

>A Contract is a collection of agreements between a client (Consumer) and an API (Provider) that describes the interactions that can take place between them.

>Consumer Driven Contracts is a pattern that drives the development of the Provider from its Consumers point of view.

>Pact is a testing tool that guarantees those Contracts are satisfied.

Read [Getting started with Pact](http://dius.com.au/2016/02/03/microservices-pact/) for more information on
how to get going.

Pact Go implements [Pact Specification v2](https://github.com/pact-foundation/pact-specification/tree/version-2),
including [flexible matching](http://docs.pact.io/documentation/matching.html).

[![asciicast](https://asciinema.org/a/121445.png)](https://asciinema.org/a/121445)

## Table of Contents

<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:1 -->

1. [Table of Contents](#table-of-contents)
2. [Installation](#installation)
3. [Running](#running)
	1. [Consumer](#consumer)
		1. [Matching (Consumer Tests)](#matching-consumer-tests)
	2. [Provider](#provider)
		1. [Provider States](#provider-states)
	3. [Publishing Pacts to a Broker and Tagging Pacts](#publishing-pacts-to-a-broker-and-tagging-pacts)
		1. [Publishing from Go code](#publishing-from-go-code)
		2. [Publishing from the CLI](#publishing-from-the-cli)
        4. [Publishing Verification Results to a Pact Broker](#publishing-verification-results-to-a-pact-broker)
	5. [Using the Pact Broker with Basic authentication](#using-the-pact-broker-with-basic-authentication)
	6. [Output Logging](#output-logging)
4. [Examples](#examples)
5. [Contact](#contact)
6. [Documentation](#documentation)
7. [Roadmap](#roadmap)
8. [Contributing](#contributing)

<!-- /TOC -->

## Installation

* Download a [release](https://github.com/pact-foundation/pact-go/releases) for your OS.
* Unzip the package into a known location, and rename `pact-go_<os/arch>` to `pact-go` and ensuring it is on the `PATH`.
* Run `pact-go` to see what options are available.
* Run `go get github.com/pact-foundation/pact-go` to install the source packages

*NOTE*: Don't despair! We are [working](https://github.com/pact-foundation/pact-go/tree/feature/native)
on a pure Go implementation that won't require this install step - please be
patient or help us implement the [roadmap](https://github.com/pact-foundation/pact-go/wiki/Native-implementation-roadmap).

## Running

Due to some design constraints, Pact Go runs a two-step process:

1. Run `pact-go daemon` in a separate process/shell. The Consumer and Provider
DSLs communicate over a local (RPC) connection, and is transparent to clients.
1. Create your Pact Consumer/Provider Tests. It defaults to run on port `6666`.

*NOTE: The daemon is completely thread safe and it is normal to leave the daemon
running for long periods (e.g. on a CI server).*

### Consumer
1. Start the daemon with `./pact-go daemon`.
1. go get github.com/pact-foundation/pact-go
1. cd $GOPATH/src/github.com/pact-foundation/pact-go/examples
1. `cd <pact-go>/examples`.
1. `go run -v consumer.go`.

Here is a simple example (`consumer_test.go`) you can run with `go test -v .`:

```go
package somepackage

import (
	"fmt"
	"github.com/pact-foundation/pact-go/dsl"
	"net/http"
{'fraction_non_alphanumeric': 0.1341492115791951, 'fraction_numerical': 0.022828900917863028, 'mean_word_length': 4.8412371134020615, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 18, 'https://': 28, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '158251', 'n_tokens_mistral': 2967, 'n_tokens_neox': 2753, 'n_words': 777}