-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publish test results): enable test results to be published to th…
…e pact broker in the verification results
- Loading branch information
Showing
12 changed files
with
248 additions
and
38 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,66 @@ | ||
require 'rspec/core/formatters' | ||
require 'pact/provider/verification_results/publish_all' | ||
|
||
module Pact | ||
module Provider | ||
module RSpec | ||
class PactBrokerFormatter < ::RSpec::Core::Formatters::BaseFormatter | ||
Pact::RSpec.with_rspec_3 do | ||
::RSpec::Core::Formatters.register self, :message, :dump_summary, :stop, :seed, :close | ||
end | ||
|
||
attr_reader :output_hash | ||
|
||
def initialize(output) | ||
super | ||
@output_hash = { | ||
:version => ::RSpec::Core::Version::STRING | ||
} | ||
end | ||
|
||
def message(notification) | ||
(@output_hash[:messages] ||= []) << notification.message | ||
end | ||
|
||
def dump_summary(summary) | ||
end | ||
|
||
def stop(notification) | ||
@output_hash[:examples] = notification.examples.map do |example| | ||
format_example(example).tap do |hash| | ||
e = example.exception | ||
if e | ||
hash[:exception] = { | ||
class: e.class.name, | ||
message: e.message | ||
} | ||
end | ||
end | ||
end | ||
end | ||
|
||
def seed(notification) | ||
return unless notification.seed_used? | ||
@output_hash[:seed] = notification.seed | ||
end | ||
|
||
def close(_notification) | ||
Pact::Provider::VerificationResults::PublishAll.call(Pact.provider_world.pact_sources, output_hash) | ||
end | ||
|
||
private | ||
|
||
def format_example(example) | ||
{ | ||
exampleDescription: example.description, | ||
fullDescription: example.full_description, | ||
status: example.execution_result.status.to_s, | ||
interactionProviderState: example.metadata[:pact_provider_state], | ||
interactionDescription: example.metadata[:pact_description], | ||
pact_uri: example.metadata[:pact_uri] | ||
} | ||
end | ||
end | ||
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
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
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,68 @@ | ||
require 'pact/provider/verification_results/publish_all' | ||
require 'pact/provider/pact_uri' | ||
|
||
describe "publishing verifications" do | ||
|
||
before do | ||
allow(Pact.configuration).to receive(:provider).and_return(provider_configuration) | ||
allow($stdout).to receive(:puts) | ||
end | ||
|
||
let(:provider_configuration) do | ||
double('provider_configuration', | ||
application_version: '1.2.3', | ||
publish_verification_results?: true, | ||
tags: []) | ||
end | ||
|
||
let(:pact_sources) do | ||
[instance_double('Pact::Provider::PactSource', pact_hash: pact_hash, uri: pact_uri)] | ||
end | ||
|
||
let(:pact_uri) do | ||
instance_double('Pact::Provider::PactURI', uri: 'pact.json', basic_auth?: false) | ||
end | ||
|
||
let(:pact_hash) do | ||
{ | ||
'_links' => { | ||
'pb:publish-verification-results' => { | ||
'href' => 'http://publish/' | ||
} | ||
} | ||
} | ||
end | ||
|
||
let(:created_verification_body) do | ||
{ | ||
'_links' => { | ||
'self' => { | ||
'href' => 'http://created' | ||
} | ||
} | ||
}.to_json | ||
end | ||
|
||
let(:test_results_hash) do | ||
{ | ||
examples: [ | ||
{ | ||
exampleDescription: '1', | ||
status: 'passed', | ||
pact_uri: pact_uri | ||
} | ||
] | ||
} | ||
end | ||
|
||
subject { Pact::Provider::VerificationResults::PublishAll.call(pact_sources, test_results_hash) } | ||
|
||
let!(:request) do | ||
stub_request(:post, 'http://publish').to_return(status: 200, body: created_verification_body) | ||
end | ||
|
||
it "publishes the results" do | ||
subject | ||
expect(request).to have_been_made | ||
end | ||
end |
Oops, something went wrong.