Giter Club home page Giter Club logo

pact-provider-verifier-docker's Introduction

Pact Provider Verification

NOTE: If you're new to Pact and have landed here, it's probably not what you want. If you simply want a Dockerized version of the verifier, the official Docker container for all Pact libraries is: https://github.com/pact-foundation/pact-ruby-cli.

This setup simplifies Pact Provider verification process in any language, by running the Pact Rake tasks in a separate Docker container.

Features:

  • Verify Pacts against Pacts published to a Pact Broker
  • Verify local *.json Pacts for testing in a development environment
  • Pre-configured Docker image with Ruby installed and a sane, default src/Rakefile keeping things DRY
  • Works with Pact provider states should you need them

Prerequisites

  • Docker
  • Docker Compose
  • Working Dockerfile for your API

Examples

Simple API

Steps:

  1. Create an API and a corresponding Docker image for it
  2. Publish Pacts to the Pact broker (or create local ones)
  3. Create a docker-compose.yml file connecting your API to the Pact Verifier
  4. Set the following required environment variables:
    • pact_urls - a comma delimited list of pact file urls
    • provider_base_url - the base url of the pact provider (i.e. your API)
  5. Run docker-compose build and then docker-compose up
Sample docker-compose.yml file for a Node API exposed on port 4000:
api:
  build: .
  command: npm start
  ports:
  - "4000:4000"

pactverifier:
  image: dius/pact-provider-verifier-docker
  links:
  - api:api
  volumes:
  - ./pact/pacts:/tmp/pacts                 # If you have local Pacts
  environment:
  - pact_urls=http://pact-host:9292/pacts/provider/MyAPI/consumer/MyConsumer/latest
  #- pact_urls=/tmp/pacts/foo-consumer.json # If you have local Pacts
  - provider_base_url=http://api:4000

API with Provider States

Execute pact provider verification against a provider which implements the following:

  • an http get endpoint which returns pact provider_states by consumer

      {
      	"myConsumer": [
      		"customer is logged in",
      		"customer has a million dollars"
      	]
      }
    
  • an http post endpoint which sets the active pact consumer and provider state

      consumer=web&state=customer%20is%20logged%20in
    

The following environment variables required:

  • pact_urls - a comma delimited list of pact file urls
  • provider_base_url - the base url of the pact provider
  • provider_states_url - the full url of the endpoint which returns provider states by consumer
  • provider_states_active_url - the full url of the endpoint which sets the active pact consumer and provider state

(non-Docker) Usage

$ bundle install
$ bundle exec rake verify_pacts

Docker Compose Usage

Sample docker-compose.yml file
api:
	build: .
	command: npm run-script pact-provider
	ports:
	- "4000"

pactverifier:
	image: dius/pact-provider-verifier-docker
	links:
	- api
	environment:
	- pact_urls=http://pact-host:9292/pacts/provider/MyProvider/consumer/myConsumer/latest
	- provider_base_url=http://api4000:
	- provider_states_url=http://api:4000/provider-states
	- provider_states_active_url=http://api:4000/provider-states/active

pact-provider-verifier-docker's People

Contributors

bethesque avatar ibotdotout avatar lextiz avatar mefellows avatar schultemarkus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pact-provider-verifier-docker's Issues

will not build

Here is the error im getting when I run docker-compose -f .\Verify_compose.yml up

Attaching to brokerimage_pactverifier_1
pactverifier_1 | /usr/local/lib/ruby/2.6.0/rubygems.rb:283:in find_spec_for_exe': Could not find 'bundler' (2.0.1) required by your /app/Gemfile.lock. (Gem::GemNotFoundException) pactverifier_1 | To update to the latest version installed on your system, run bundle update --bundler. pactverifier_1 | To install the missing version, run gem install bundler:2.0.1pactverifier_1 | from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:inactivate_bin_path'
pactverifier_1 | from /usr/local/bundle/bin/bundle:23:in `

'
brokerimage_pactverifier_1 exited with code 1

failing with NoMethodError: undefined method `strip’ for #<Pact::SomethingLike:0x0056250360f170>

Hi,
I have an interaction generated using pact spec version 2.0.0 within which sits a matcher for a UUID header-
{
"request": {
"method": "GET",
"headers": {
"Accept": "application/json, text/plain, /",
"id": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$"
},
"matchingRules": {
"$.headers.id": {
"match": "type"
}

I run the dockerised version of pact-provider-verifier, and receive the subject error.
what can be done to resolve this and allow us to continue using matchers to define headers in interactions?
I'm not sure what further info would be helpful, please let me know if any.
this feels similar to #115, but wondered if anything more could be done 2 years on from this.

thanks in advance

Verification Results not being uploaded

After successfully using the verifier image, pulling pacts down from a broker, and successfully verifying the pacts, the results are not being published to that broker

How do I supply broker basic authentication?

I have the below docker-compase.yml file which looks like trying to authentication with the broker to get the consumer. I cannot find a sample of using authentication:

docker-compose

pactverifier:
  image: dius/pact-provider-verifier-docker
  depends_on:
  - api
  links:
  - api:api
  environment:
    provider: 'GraphQL-Test-Provider'
    provider_base_url: 'http://api:5000'
    pact_urls: 'http://x.x.x.x:1234'
    pact_broker_base_url: 'http://x.x.x.x:1234'
    broker_username: 'cli user'
    broker_password: 'cli password'

output

pactverifier_1  | WARN: the following non-mandatory environment variables have not been specified: '["provider_states_url", "provider_states_active_url"]'
api_1           | πŸš€ GraphQL server ready at http://localhost:5000/graphql
pactverifier_1  | rake aborted!
pactverifier_1  | NoMethodError: undefined method `[]' for nil:NilClass
pactverifier_1  | /app/Rakefile:24:in `get_pact_consumer_name'
pactverifier_1  | /app/Rakefile:30:in `block (3 levels) in <top (required)>'
pactverifier_1  | /usr/local/bundle/gems/pact-provider-proxy-2.1.0/lib/pact/provider/proxy/tasks/proxy_verification_task.rb:12:in `initialize'
pactverifier_1  | /app/Rakefile:29:in `new'
pactverifier_1  | /app/Rakefile:29:in `block (2 levels) in <top (required)>'
pactverifier_1  | /app/Rakefile:28:in `each'
pactverifier_1  | /app/Rakefile:28:in `block in <top (required)>'
pactverifier_1  | /usr/local/bundle/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
pactverifier_1  | /usr/local/bin/bundle:23:in `load'
pactverifier_1  | /usr/local/bin/bundle:23:in `<main>'
pactverifier_1  | Tasks: TOP => verify_pacts
pactverifier_1  | (See full trace by running task with --trace)
graphql-test_pactverifier_1 exited with code 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.