Coder Social home page Coder Social logo

andrewspinks / pact-provider-proxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pact-foundation/pact-provider-proxy

0.0 2.0 0.0 109 KB

Allows pact verification against a running provider at a configurable base URL

License: MIT License

Ruby 100.00%

pact-provider-proxy's Introduction

Pact::Provider::Proxy

Allows pact verification against a running provider at a configurable base URL (normal pact verification is run against a code base using Rack::Test::Methods - no process is actually spawned).

This allows testing against providers where you have access to a running instance of a provider, but you do not have access to its code base, or where the provider is not a ruby application.

Installation

Add this line to your application's Gemfile:

gem 'pact-provider-proxy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pact-provider-proxy

Usage

Usually, you would configure and run pact:verify in the provider code base. If you are using pact-provider-proxy to run your pact verify task, it is probably because you don't have access to the code base of the provider project, or it is not a ruby project, so it may make sense to include this task in your consumer project.

Specifying a pact_helper is optional, and is only required if you are using provider states.

require 'pact/provider/proxy/tasks'

Pact::ProxyVerificationTask.new :monolith do | task |
 task.pact_url './spec/pacts/my-consumer_my-monolith.json', :pact_helper => './spec/support/monolith_pact_helper'
 task.provider_base_url 'http://my-monolith'
end

Then run:

$ rake pact:verify:monolith

If you have access to your provider code base, and are able to spawn an instance locally, you could add some rake tasks to start and stop your server. (Please note, I have not actually run this code, I just think it should work...)

Pact::ProxyVerificationTask.new :running_local_monolith do | task |
 task.pact_url './spec/pacts/my-consumer_my-local-monolith.json'
 task.provider_base_url 'http://localhost:8080'
end

task :start_provider do
  system "./provider_start -p 8080"
end

task :stop_provider do
  system "./provider_stop"
end

task 'pact:verify:local_monolith' do
  begin
    Rake::Task['start_provider'].execute
    Rake::Task['pact:verify:running_local_monolith'].execute
  ensure
    Rake::Task['stop_provider'].execute
  end
end

If a ruby adapter to the underlying datastore cannot be used to set up provider states, shell scripts that invoke code in the native language might work. If you have access to the code base, another alternative could be to provide an endpoint on your app that sets up data inside itself, that is only mounted in test mode. eg 'http://localhost:8080/set-up-provider-state?name=a%20thing%20exists' and 'http://localhost:8080/tear-down-provider-state?name=a%20thing%20exists'

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

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.