Skip to content

Commit

Permalink
feat: maintain path portion of specified provider base URL
Browse files Browse the repository at this point in the history
This allows /foo to be replayed against http://provider/bar/foo

For pact-foundation/pact-js#131
  • Loading branch information
bethesque committed Dec 7, 2017
1 parent 58aea41 commit b765b00
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def configure_reverse_proxy
preserve_host: true,
x_forwarded_headers: false
)
reverse_proxy '/', provider_base_url
reverse_proxy /(.*)/, "#{provider_base_url}$1"
end
end

Expand Down
23 changes: 23 additions & 0 deletions spec/integration_with_prefix_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'json'

describe "pact-provider-verifier with a prefix path in the base URL" do
before(:all) do
@pipe = IO.popen("bundle exec rackup -p 5837 spec/support/config_with_prefix.ru")
sleep 2
end

subject { `bundle exec bin/pact-provider-verifier spec/support/pacts/prefix.json -a 1 --provider-base-url http://localhost:5837/prefix -v` }

it "exits with a 0 exit code" do
subject
expect($?).to eq 0
end

it "the output contains a success message" do
expect(subject).to include "1 interaction, 0 failures"
end

after(:all) do
Process.kill 'KILL', @pipe.pid
end
end
3 changes: 3 additions & 0 deletions spec/support/config_with_prefix.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative 'provider_with_prefix'

run Provider
26 changes: 26 additions & 0 deletions spec/support/pacts/prefix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"consumer": {
"name": "me"
},
"provider": {
"name": "they"
},
"interactions": [
{
"description": "Greeting",
"request": {
"method": "GET",
"path": "/foo"
},
"response": {
"status": 200,
"body": {
"greeting": "Hello"
}
}
}]
,
"metadata": {
"pactSpecificationVersion": "2.0.0"
}
}
10 changes: 10 additions & 0 deletions spec/support/provider_with_prefix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'sinatra'
require 'sinatra/base'
require 'sinatra/json'
require 'json'

class Provider < Sinatra::Base
get '/prefix/foo' do
json :greeting => 'Hello'
end
end

0 comments on commit b765b00

Please sign in to comment.