-
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.
feat: add message pact verification support - alpha release only
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 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
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,31 @@ | ||
require 'pact/provider_verifier/app' | ||
|
||
RSpec.describe "verifying a message pact" do | ||
|
||
before(:all) do | ||
@pipe = IO.popen("rackup -p 9393 spec/support/message_producer_verifier.ru") | ||
sleep 2 | ||
end | ||
|
||
let(:pact_path) { './spec/support/pacts/message-pact-v3-pass.json' } | ||
|
||
subject { `bundle exec bin/pact-provider-verifier #{pact_path} -a 1.0.100 --provider-base-url http://localhost:9393 2>&1` } | ||
|
||
context "when verification passes" do | ||
it do | ||
expect(subject).to include("1 interaction, 0 failures") | ||
end | ||
end | ||
|
||
context "when verification fails" do | ||
let(:pact_path) { './spec/support/pacts/message-pact-v3-fail.json' } | ||
|
||
it do | ||
expect(subject).to include("1 interaction, 1 failure") | ||
end | ||
end | ||
|
||
after(:all) do | ||
Process.kill 'KILL', @pipe.pid | ||
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,39 @@ | ||
# TODO provider states | ||
|
||
require 'json' | ||
|
||
class Provider | ||
def a_test_message | ||
{ | ||
text: "Hello world!!" | ||
} | ||
end | ||
end | ||
|
||
class MessageCreator | ||
def initialize provider | ||
@provider = provider | ||
end | ||
|
||
def create message_descriptor | ||
message_creation_method = message_descriptor.description.downcase.gsub(' ', '_').to_sym | ||
message_content = @provider.send(message_creation_method) | ||
{ content: message_content } | ||
end | ||
end | ||
|
||
class HttpRequestHandler | ||
def initialize message_creator | ||
@message_creator = message_creator | ||
end | ||
|
||
def call env | ||
request_body = JSON.parse(env['rack.input'].read) | ||
message_descriptor = OpenStruct.new(request_body) | ||
response_body = @message_creator.create(message_descriptor) | ||
[200, {'Content-Type' => 'application/json'}, [response_body.to_json]] | ||
end | ||
|
||
end | ||
|
||
run HttpRequestHandler.new(MessageCreator.new(Provider.new)) |
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,11 @@ | ||
{ | ||
"consumer": {"name": "Foo"}, | ||
"provider": {"name": "Bar"}, | ||
"messages": [{ | ||
"description": "a test message", | ||
"content": { | ||
"text": "Hello world!!!" | ||
} | ||
} | ||
] | ||
} |
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,11 @@ | ||
{ | ||
"consumer": {"name": "Foo"}, | ||
"provider": {"name": "Bar"}, | ||
"messages": [{ | ||
"description": "a test message", | ||
"content": { | ||
"text": "Hello world!!" | ||
} | ||
} | ||
] | ||
} |