-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from pact-foundation/feat/v3_generators
Feat/v3 generators
- Loading branch information
Showing
7 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'json' | ||
|
||
describe "pact-provider-verifier with a provider state injected to a pact file" do | ||
before(:all) do | ||
@pipe = IO.popen("bundle exec rackup -p 5837 spec/support/provider_with_state_generator.rb") | ||
sleep 2 | ||
end | ||
|
||
subject { `bundle exec bin/pact-provider-verifier spec/support/pacts/pact-with-provider-state-in-headers.json -a 1 --provider-base-url http://localhost:5837/ --provider-states-setup-url http://localhost:5837/provider_state -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 | ||
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ | ||
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1") | ||
else | ||
Process.kill 'KILL', @pipe.pid | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'json' | ||
|
||
describe "pact-provider-verifier with a provider state injected to a pact file" do | ||
before(:all) do | ||
@pipe = IO.popen("bundle exec rackup -p 5837 spec/support/provider_with_state_generator.rb") | ||
sleep 2 | ||
end | ||
|
||
subject { `bundle exec bin/pact-provider-verifier spec/support/pacts/pact-with-provider-state-in-path.json -a 1 --provider-base-url http://localhost:5837/ --provider-states-setup-url http://localhost:5837/provider_state -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 | ||
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ | ||
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1") | ||
else | ||
Process.kill 'KILL', @pipe.pid | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
spec/support/pacts/pact-with-provider-state-in-headers.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"provider": { | ||
"name": "Foo" | ||
}, | ||
"consumer": { | ||
"name": "Bar" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "requires access token", | ||
"request": { | ||
"method": "GET", | ||
"path": "/requires_auth", | ||
"headers": { | ||
"Authorization": "Bearer EXAMPLE_TOKEN" | ||
}, | ||
"generators": { | ||
"header": { | ||
"$.Authorization": { | ||
"expression": "Bearer ${accessToken}", | ||
"type": "ProviderState" | ||
} | ||
} | ||
} | ||
}, | ||
"response": { | ||
"status": 200 | ||
}, | ||
"providerStates": [ | ||
{ | ||
"name": "returns access token" | ||
} | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"pactSpecification": { | ||
"version": "3.0.0" | ||
}, | ||
"pact-jvm": { | ||
"version": "4.0.5" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"provider": { | ||
"name": "Foo" | ||
}, | ||
"consumer": { | ||
"name": "Bar" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "returns book detail", | ||
"request": { | ||
"method": "GET", | ||
"path": "/book/1", | ||
"generators": { | ||
"path": { | ||
"type": "ProviderState", | ||
"expression": "/book/${id}" | ||
} | ||
} | ||
}, | ||
"response": { | ||
"status": 200, | ||
"body": { | ||
"name": "Injected Book" | ||
} | ||
}, | ||
"providerStates": [ | ||
{ | ||
"name": "returns book detail" | ||
} | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"pactSpecification": { | ||
"version": "3.0.0" | ||
}, | ||
"pact-jvm": { | ||
"version": "4.0.5" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'sinatra' | ||
require 'sinatra/base' | ||
require 'sinatra/json' | ||
require 'json' | ||
|
||
class ProviderWithStateGenerator < Sinatra::Base | ||
post '/provider_state' do | ||
json :id => 2, :accessToken => 'INJECTED_TOKEN' | ||
end | ||
|
||
get '/book/1' do | ||
# Return 404 so that if the provider state is not injected the contract will fail | ||
status 404 | ||
json :id => 1, :name => 'Book not found' | ||
end | ||
|
||
get '/book/2' do | ||
json :id => 2, :name => 'Injected Book' | ||
end | ||
|
||
get '/requires_auth' do | ||
if request.env['HTTP_AUTHORIZATION'] != "Bearer INJECTED_TOKEN" | ||
status 403 | ||
end | ||
end | ||
|
||
end |