Skip to content

Commit b347588

Browse files
committedNov 16, 2017
fix(verifications): tag provider version, not consumer version
1 parent cd2b79e commit b347588

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed
 

‎lib/pact/provider/verification_results/publish.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ def publication_url
5050
end
5151

5252
def tag_url tag
53-
href = pact_source.pact_hash.fetch('_links', {}).fetch('pb:tag-version', {})['href']
54-
href ? href.gsub('{tag}', tag) : nil
53+
# This is so dodgey, need to use proper HAL
54+
if publication_url
55+
u = URI(publication_url)
56+
if match = publication_url.match(%r{/provider/([^/]+)})
57+
provider_name = match[1]
58+
base_url = "#{u.scheme}://#{u.host}:#{u.host == u.default_port ? '' : u.port}"
59+
provider_application_version = Pact.configuration.provider.application_version
60+
"#{base_url}/pacticipants/#{provider_name}/versions/#{provider_application_version}/tags/#{tag}"
61+
end
62+
end
5563
end
5664

5765
def tag_versions_if_configured
5866
if Pact.configuration.provider.tags.any?
59-
if tag_url('')
60-
tag_versions
61-
else
62-
Pact.configuration.error_stream.puts "WARN: Cannot tag provider version as there is no link named pb:tag-version in the pact JSON."
63-
end
67+
tag_versions if tag_url('')
6468
end
6569
end
6670

‎spec/lib/pact/provider/verification_results/publish_spec.rb

+15-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module VerificationResults
66
describe Publish do
77
describe "call" do
88
let(:publish_verification_url) { nil }
9+
let(:stubbed_publish_verification_url) { 'http://broker/something/provider/Bar/verifications' }
910
let(:tag_version_url) { 'http://tag-me/{tag}' }
1011
let(:pact_source) { instance_double("Pact::Provider::PactSource", pact_hash: pact_hash, uri: pact_url)}
1112
let(:pact_url) { instance_double("Pact::Provider::PactURI", basic_auth?: basic_auth, username: 'username', password: 'password')}
@@ -18,8 +19,7 @@ module VerificationResults
1819
'_links' => {
1920
'pb:publish-verification-results'=> {
2021
'href' => publish_verification_url
21-
},
22-
'pb:tag-version'=> {'href' => tag_version_url}
22+
}
2323
}
2424
}
2525
end
@@ -46,30 +46,30 @@ module VerificationResults
4646
end
4747

4848
let(:provider_configuration) do
49-
double('provider config', publish_verification_results?: publish_verification_results, tags: tags)
49+
double('provider config', publish_verification_results?: publish_verification_results, tags: tags, application_version: '1.2.3')
5050
end
5151

5252
before do
5353
allow($stdout).to receive(:puts)
5454
allow(Pact.configuration).to receive(:provider).and_return(provider_configuration)
55-
stub_request(:post, 'http://broker/verifications').to_return(status: 200, body: created_verification_body)
56-
stub_request(:put, /tag-me/)
55+
stub_request(:post, stubbed_publish_verification_url).to_return(status: 200, body: created_verification_body)
56+
stub_request(:put, 'http://broker/pacticipants/Bar/versions/1.2.3/tags/foo')
5757
end
5858

5959
subject { Publish.call(pact_source, verification) }
6060

6161
context "when publish_verification_results is false" do
6262
it "does not publish the verification" do
6363
subject
64-
expect(WebMock).to_not have_requested(:post, 'http://broker/verifications')
64+
expect(WebMock).to_not have_requested(:post, 'http://broker/something/provider/Bar/verifications')
6565
end
6666
end
6767

6868
context "when publish_verification_results is true" do
6969
let(:publish_verification_results) { true }
7070

7171
context "when the publish-verification link is present" do
72-
let(:publish_verification_url) { 'http://broker/verifications' }
72+
let(:publish_verification_url) { stubbed_publish_verification_url }
7373

7474
it "publishes the verification" do
7575
subject
@@ -81,7 +81,7 @@ module VerificationResults
8181

8282
it "does not publish the verification" do
8383
subject
84-
expect(WebMock).to_not have_requested(:post, 'http://broker/verifications')
84+
expect(WebMock).to_not have_requested(:post, stubbed_publish_verification_url)
8585
end
8686
end
8787

@@ -90,17 +90,17 @@ module VerificationResults
9090

9191
it "tags the provider version" do
9292
subject
93-
expect(WebMock).to have_requested(:put, 'http://tag-me/foo').with(headers: {'Content-Type' => 'application/json'})
93+
expect(WebMock).to have_requested(:put, 'http://broker/pacticipants/Bar/versions/1.2.3/tags/foo').with(headers: {'Content-Type' => 'application/json'})
9494
end
9595

96-
context "when there is no pb:tag-version link" do
96+
context "when there is no pb:publish-verification-results link" do
9797
before do
98-
pact_hash['_links'].delete('pb:tag-version')
98+
pact_hash['_links'].delete('pb:publish-verification-results')
9999
end
100100

101-
it "prints a warning" do
102-
expect($stderr).to receive(:puts).with /WARN: Cannot tag provider version/
101+
it "does not tag the version" do
103102
subject
103+
expect(WebMock).to_not have_requested(:put, /.*/)
104104
end
105105
end
106106
end
@@ -127,7 +127,7 @@ module VerificationResults
127127

128128
context "when an HTTP error is returned" do
129129
it "raises a PublicationError" do
130-
stub_request(:post, 'http://broker/verifications').to_return(status: 500, body: 'some error')
130+
stub_request(:post, stubbed_publish_verification_url).to_return(status: 500, body: 'some error')
131131
expect{ subject }.to raise_error(PublicationError, /Error returned/)
132132
end
133133
end
@@ -143,7 +143,7 @@ module VerificationResults
143143
before do
144144
stub_request(:post, publish_verification_url).to_return(status: 200, body: created_verification_body)
145145
end
146-
let(:publish_verification_url) { 'https://broker/verifications' }
146+
let(:publish_verification_url) { stubbed_publish_verification_url.gsub('http', 'https') }
147147

148148
it "uses ssl" do
149149
subject

0 commit comments

Comments
 (0)