From b3475884d589f4bcf92943df296de4187f0a9498 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 16 Nov 2017 14:53:27 +1100 Subject: [PATCH] fix(verifications): tag provider version, not consumer version --- .../provider/verification_results/publish.rb | 18 ++++++----- .../verification_results/publish_spec.rb | 30 +++++++++---------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/pact/provider/verification_results/publish.rb b/lib/pact/provider/verification_results/publish.rb index bda03458..dff411fc 100644 --- a/lib/pact/provider/verification_results/publish.rb +++ b/lib/pact/provider/verification_results/publish.rb @@ -50,17 +50,21 @@ def publication_url end def tag_url tag - href = pact_source.pact_hash.fetch('_links', {}).fetch('pb:tag-version', {})['href'] - href ? href.gsub('{tag}', tag) : nil + # This is so dodgey, need to use proper HAL + if publication_url + u = URI(publication_url) + if match = publication_url.match(%r{/provider/([^/]+)}) + provider_name = match[1] + base_url = "#{u.scheme}://#{u.host}:#{u.host == u.default_port ? '' : u.port}" + provider_application_version = Pact.configuration.provider.application_version + "#{base_url}/pacticipants/#{provider_name}/versions/#{provider_application_version}/tags/#{tag}" + end + end end def tag_versions_if_configured if Pact.configuration.provider.tags.any? - if tag_url('') - tag_versions - else - Pact.configuration.error_stream.puts "WARN: Cannot tag provider version as there is no link named pb:tag-version in the pact JSON." - end + tag_versions if tag_url('') end end diff --git a/spec/lib/pact/provider/verification_results/publish_spec.rb b/spec/lib/pact/provider/verification_results/publish_spec.rb index a0ef0cc6..8ef76666 100644 --- a/spec/lib/pact/provider/verification_results/publish_spec.rb +++ b/spec/lib/pact/provider/verification_results/publish_spec.rb @@ -6,6 +6,7 @@ module VerificationResults describe Publish do describe "call" do let(:publish_verification_url) { nil } + let(:stubbed_publish_verification_url) { 'http://broker/something/provider/Bar/verifications' } let(:tag_version_url) { 'http://tag-me/{tag}' } let(:pact_source) { instance_double("Pact::Provider::PactSource", pact_hash: pact_hash, uri: pact_url)} let(:pact_url) { instance_double("Pact::Provider::PactURI", basic_auth?: basic_auth, username: 'username', password: 'password')} @@ -18,8 +19,7 @@ module VerificationResults '_links' => { 'pb:publish-verification-results'=> { 'href' => publish_verification_url - }, - 'pb:tag-version'=> {'href' => tag_version_url} + } } } end @@ -46,14 +46,14 @@ module VerificationResults end let(:provider_configuration) do - double('provider config', publish_verification_results?: publish_verification_results, tags: tags) + double('provider config', publish_verification_results?: publish_verification_results, tags: tags, application_version: '1.2.3') end before do allow($stdout).to receive(:puts) allow(Pact.configuration).to receive(:provider).and_return(provider_configuration) - stub_request(:post, 'http://broker/verifications').to_return(status: 200, body: created_verification_body) - stub_request(:put, /tag-me/) + stub_request(:post, stubbed_publish_verification_url).to_return(status: 200, body: created_verification_body) + stub_request(:put, 'http://broker/pacticipants/Bar/versions/1.2.3/tags/foo') end subject { Publish.call(pact_source, verification) } @@ -61,7 +61,7 @@ module VerificationResults context "when publish_verification_results is false" do it "does not publish the verification" do subject - expect(WebMock).to_not have_requested(:post, 'http://broker/verifications') + expect(WebMock).to_not have_requested(:post, 'http://broker/something/provider/Bar/verifications') end end @@ -69,7 +69,7 @@ module VerificationResults let(:publish_verification_results) { true } context "when the publish-verification link is present" do - let(:publish_verification_url) { 'http://broker/verifications' } + let(:publish_verification_url) { stubbed_publish_verification_url } it "publishes the verification" do subject @@ -81,7 +81,7 @@ module VerificationResults it "does not publish the verification" do subject - expect(WebMock).to_not have_requested(:post, 'http://broker/verifications') + expect(WebMock).to_not have_requested(:post, stubbed_publish_verification_url) end end @@ -90,17 +90,17 @@ module VerificationResults it "tags the provider version" do subject - expect(WebMock).to have_requested(:put, 'http://tag-me/foo').with(headers: {'Content-Type' => 'application/json'}) + expect(WebMock).to have_requested(:put, 'http://broker/pacticipants/Bar/versions/1.2.3/tags/foo').with(headers: {'Content-Type' => 'application/json'}) end - context "when there is no pb:tag-version link" do + context "when there is no pb:publish-verification-results link" do before do - pact_hash['_links'].delete('pb:tag-version') + pact_hash['_links'].delete('pb:publish-verification-results') end - it "prints a warning" do - expect($stderr).to receive(:puts).with /WARN: Cannot tag provider version/ + it "does not tag the version" do subject + expect(WebMock).to_not have_requested(:put, /.*/) end end end @@ -127,7 +127,7 @@ module VerificationResults context "when an HTTP error is returned" do it "raises a PublicationError" do - stub_request(:post, 'http://broker/verifications').to_return(status: 500, body: 'some error') + stub_request(:post, stubbed_publish_verification_url).to_return(status: 500, body: 'some error') expect{ subject }.to raise_error(PublicationError, /Error returned/) end end @@ -143,7 +143,7 @@ module VerificationResults before do stub_request(:post, publish_verification_url).to_return(status: 200, body: created_verification_body) end - let(:publish_verification_url) { 'https://broker/verifications' } + let(:publish_verification_url) { stubbed_publish_verification_url.gsub('http', 'https') } it "uses ssl" do subject