pact_broker-client 1.70.0 → 1.72.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
+ require "yaml"
1
2
  require_relative "pact_helper"
2
3
  require "pactflow/client/provider_contracts/publish"
3
- require "yaml"
4
4
 
5
5
  RSpec.describe "publishing a provider contract to PactFlow", pact: true do
6
6
  before do
7
- # no point re-testing this
8
- allow(PactBroker::Client::Versions::Create).to receive(:call).and_return(double("result", success: true))
7
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
9
9
  end
10
10
 
11
11
  include_context "pact broker"
@@ -17,8 +17,9 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
17
17
  provider_version_number: "1",
18
18
  branch_name: "main",
19
19
  tags: ["dev"],
20
+ build_url: "http://build",
20
21
  contract: {
21
- content: { some: "contract" }.to_yaml,
22
+ content: { "some" => "contract" }.to_yaml,
22
23
  content_type: "application/yaml",
23
24
  specification: "oas"
24
25
  },
@@ -33,14 +34,17 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
33
34
  }
34
35
  end
35
36
 
36
- let(:body) { { some: "body" }.to_json }
37
-
38
37
  let(:request_body) do
39
38
  {
40
- "content" => "LS0tCjpzb21lOiBjb250cmFjdAo=",
41
- "contractType" => "oas",
39
+ "pacticipantVersionNumber" => "1",
40
+ "tags" => ["dev"],
41
+ "branch" => "main",
42
+ "buildUrl" => "http://build",
43
+ "contract" => {
44
+ "content" => "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
42
45
  "contentType" => "application/yaml",
43
- "verificationResults" => {
46
+ "specification" => "oas",
47
+ "selfVerificationResults" => {
44
48
  "success" => true,
45
49
  "content" => "c29tZSByZXN1bHRz",
46
50
  "contentType" => "text/plain",
@@ -48,14 +52,36 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
48
52
  "verifier" => "my custom tool",
49
53
  "verifierVersion" => "1.0"
50
54
  }
55
+ }
51
56
  }
52
57
  end
53
58
 
54
- let(:response_status) { 201 }
59
+ let(:response_status) { 200 }
60
+
61
+ # Can't tell from the response if the buildUrl was correct, but it's not that important
62
+ # Add some assertions to the body to ensure we have called the endpoint correctly,
63
+ # not because we use the properties in the CLI output.
64
+ # There is unfortunately no good way to determine from the response whether or not
65
+ # we have correctly published the self verification results.
55
66
  let(:success_response) do
56
67
  {
57
68
  status: response_status,
58
- headers: pact_broker_response_headers
69
+ headers: pact_broker_response_headers,
70
+ body: {
71
+ "notices" => Pact.each_like("text" => "some notice", "type" => "info"),
72
+ "_embedded" => {
73
+ "version" => {
74
+ # This tells us we have set the version number correctly
75
+ "number" => "1"
76
+ }
77
+ },
78
+ "_links" => {
79
+ # The links tell us we have successfully created the tags, but we don't care about the contents
80
+ "pb:pacticipant-version-tags" => [{}],
81
+ # The link tells us we have successfully created the branch version, but we don't care about the contents
82
+ "pb:branch-version" => {},
83
+ }
84
+ }
59
85
  }
60
86
  end
61
87
 
@@ -74,54 +100,38 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
74
100
  context "creating a provider contract with valid parameters" do
75
101
  before do
76
102
  pactflow
77
- .upon_receiving("a request to create a provider contract")
103
+ .given("the pb:publish-provider-contract relation exists in the index resource")
104
+ .upon_receiving("a request for the index resource")
78
105
  .with(
79
- method: :put,
80
- path: "/contracts/provider/Bar/version/1",
81
- headers: put_request_headers,
82
- body: request_body)
83
- .will_respond_with(success_response)
84
- end
85
-
86
- it "returns a CommandResult with success = true" do
87
- expect(subject).to be_a PactBroker::Client::CommandResult
88
- expect(subject.success).to be true
89
- expect(subject.message).to include "Successfully published provider contract for Bar version 1"
90
- expect(subject.message).not_to include pactflow.mock_service_base_url
91
- end
92
- end
93
-
94
- context "creating a provider contract with valid parameters with pf:ui return results" do
95
- let(:success_response_with_pf_ui_url) do
96
- {
97
- status: response_status,
98
- headers: pact_broker_response_headers,
99
- body: { "_links": {
100
- "pf:ui": {
101
- "href": "#{pactflow.mock_service_base_url}/contracts/bi-directional/provider/Bar/version/1/provider-contract"
106
+ method: "GET",
107
+ path: "/",
108
+ headers: get_request_headers
109
+ ).will_respond_with(
110
+ status: 200,
111
+ headers: pact_broker_response_headers,
112
+ body: {
113
+ _links: {
114
+ :'pf:publish-provider-contract' => {
115
+ href: placeholder_url_term("pf:publish-provider-contract", ['provider'], pactflow)
116
+ }
117
+ }
102
118
  }
103
- } }
104
- }
105
- end
106
- before do
119
+ )
120
+
107
121
  pactflow
108
- .given("there is a pf:ui href in the response")
109
- .upon_receiving("a request to create a provider contract")
122
+ .upon_receiving("a request to publish a provider contract")
110
123
  .with(
111
- method: :put,
112
- path: "/contracts/provider/Bar/version/1",
113
- headers: put_request_headers,
114
- body: request_body
115
- )
116
- .will_respond_with(success_response_with_pf_ui_url)
124
+ method: :post,
125
+ path: placeholder_path("pf:publish-provider-contract", ["Bar"]),
126
+ headers: post_request_headers,
127
+ body: request_body
128
+ ).will_respond_with(success_response)
117
129
  end
118
130
 
119
- it "returns a CommandResult with success = true and a provider contract ui url" do
131
+ it "returns a CommandResult with success = true" do
120
132
  expect(subject).to be_a PactBroker::Client::CommandResult
121
133
  expect(subject.success).to be true
122
- expect(subject.message).to include "Successfully published provider contract for Bar version 1"
123
- expect(subject.message).to include "Next steps:"
124
- expect(subject.message).to include success_response_with_pf_ui_url[:body][:_links][:'pf:ui'][:href]
134
+ expect(subject.message).to include "some notice"
125
135
  end
126
136
  end
127
- end
137
+ end
@@ -0,0 +1,129 @@
1
+ require_relative "pact_helper"
2
+ require "yaml"
3
+ require "pactflow/client/provider_contracts/publish_the_old_way"
4
+ require "pact_broker/client/versions/create"
5
+
6
+
7
+ RSpec.describe "publishing a provider contract to PactFlow the old way", pact: true do
8
+ before do
9
+ # no point re-testing this
10
+ allow(PactBroker::Client::Versions::Create).to receive(:call).and_return(double("result", success: true))
11
+ end
12
+
13
+ include_context "pact broker"
14
+ include PactBrokerPactHelperMethods
15
+
16
+ let(:command_params) do
17
+ {
18
+ provider_name: "Bar",
19
+ provider_version_number: "1",
20
+ branch_name: "main",
21
+ tags: ["dev"],
22
+ contract: {
23
+ content: { "some" => "contract" }.to_yaml,
24
+ content_type: "application/yaml",
25
+ specification: "oas"
26
+ },
27
+ verification_results: {
28
+ success: true,
29
+ content: "some results",
30
+ content_type: "text/plain",
31
+ format: "text",
32
+ verifier: "my custom tool",
33
+ verifier_version: "1.0"
34
+ }
35
+ }
36
+ end
37
+
38
+ let(:body) { { some: "body" }.to_json }
39
+
40
+ let(:request_body) do
41
+ {
42
+ "content" => "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
43
+ "contractType" => "oas",
44
+ "contentType" => "application/yaml",
45
+ "verificationResults" => {
46
+ "success" => true,
47
+ "content" => "c29tZSByZXN1bHRz",
48
+ "contentType" => "text/plain",
49
+ "format" => "text",
50
+ "verifier" => "my custom tool",
51
+ "verifierVersion" => "1.0"
52
+ }
53
+ }
54
+ end
55
+
56
+ let(:response_status) { 201 }
57
+ let(:success_response) do
58
+ {
59
+ status: response_status,
60
+ headers: pact_broker_response_headers
61
+ }
62
+ end
63
+
64
+ let(:options) do
65
+ {
66
+ verbose: false
67
+ }
68
+ end
69
+
70
+ let(:pact_broker_client_options) do
71
+ { pact_broker_base_url: pactflow.mock_service_base_url }
72
+ end
73
+
74
+ subject { Pactflow::Client::ProviderContracts::PublishTheOldWay.call(command_params, options, pact_broker_client_options) }
75
+
76
+ context "creating a provider contract with valid parameters" do
77
+ before do
78
+ pactflow
79
+ .upon_receiving("a request to create a provider contract")
80
+ .with(
81
+ method: :put,
82
+ path: "/contracts/provider/Bar/version/1",
83
+ headers: put_request_headers,
84
+ body: request_body)
85
+ .will_respond_with(success_response)
86
+ end
87
+
88
+ it "returns a CommandResult with success = true" do
89
+ expect(subject).to be_a PactBroker::Client::CommandResult
90
+ expect(subject.success).to be true
91
+ expect(subject.message).to include "Successfully published provider contract for Bar version 1"
92
+ expect(subject.message).not_to include pactflow.mock_service_base_url
93
+ end
94
+ end
95
+
96
+ context "creating a provider contract with valid parameters with pf:ui return results" do
97
+ let(:success_response_with_pf_ui_url) do
98
+ {
99
+ status: response_status,
100
+ headers: pact_broker_response_headers,
101
+ body: { "_links": {
102
+ "pf:ui": {
103
+ "href": Pact.like("some-url")
104
+ }
105
+ } }
106
+ }
107
+ end
108
+ before do
109
+ pactflow
110
+ .given("there is a pf:ui href in the response")
111
+ .upon_receiving("a request to create a provider contract")
112
+ .with(
113
+ method: :put,
114
+ path: "/contracts/provider/Bar/version/1",
115
+ headers: put_request_headers,
116
+ body: request_body
117
+ )
118
+ .will_respond_with(success_response_with_pf_ui_url)
119
+ end
120
+
121
+ it "returns a CommandResult with success = true and a provider contract ui url" do
122
+ expect(subject).to be_a PactBroker::Client::CommandResult
123
+ expect(subject.success).to be true
124
+ expect(subject.message).to include "Successfully published provider contract for Bar version 1"
125
+ expect(subject.message).to include "Next steps:"
126
+ expect(subject.message).to include "some-url"
127
+ end
128
+ end
129
+ end
data/spec/spec_helper.rb CHANGED
@@ -33,6 +33,10 @@ RSpec.configure do | config |
33
33
  eval "$#{stream} = StringIO.new"
34
34
  yield
35
35
  result = eval("$#{stream}").string
36
+ rescue SystemExit => e
37
+ puts "CAUGHT SYSTEM EXIT"
38
+ puts e
39
+ puts e.backtrace
36
40
  ensure
37
41
  eval("$#{stream} = #{stream.upcase}")
38
42
  end
data/tasks/pact.rake CHANGED
@@ -2,7 +2,7 @@ require "pact_broker/client/tasks"
2
2
  require "pact_broker/client/git"
3
3
 
4
4
  PactBroker::Client::PublicationTask.new(:localhost) do | task |
5
- require 'pact_broker/client/version'
5
+ require "pact_broker/client/version"
6
6
  task.tag = `git rev-parse --abbrev-ref HEAD`.strip
7
7
  task.consumer_version = PactBroker::Client::VERSION
8
8
  task.pact_broker_base_url = "http://localhost:9292"
@@ -11,17 +11,17 @@ PactBroker::Client::PublicationTask.new(:localhost) do | task |
11
11
  end
12
12
 
13
13
  PactBroker::Client::PublicationTask.new(:remote) do | task |
14
- require 'pact_broker/client/version'
14
+ require "pact_broker/client/version"
15
15
  task.tag = `git rev-parse --abbrev-ref HEAD`.strip
16
16
  task.consumer_version = PactBroker::Client::VERSION
17
17
  task.pact_broker_base_url = "https://test.pact.dius.com.au"
18
- task.pact_broker_basic_auth = { username: ENV.fetch('PACT_BROKER_USERNAME'), password: ENV.fetch('PACT_BROKER_PASSWORD') }
18
+ task.pact_broker_basic_auth = { username: ENV.fetch("PACT_BROKER_USERNAME"), password: ENV.fetch("PACT_BROKER_PASSWORD") }
19
19
  end
20
20
 
21
- PactBroker::Client::PublicationTask.new(:pactflow) do | task |
22
- version = ENV.fetch('GITHUB_SHA')
23
- branch = ENV.fetch('GITHUB_REF').gsub("refs/heads/", "")
24
- feature = ENV.fetch('TEST_FEATURE', '')
21
+ PactBroker::Client::PublicationTask.new(:pactflow_oss) do | task |
22
+ version = ENV.fetch("GITHUB_SHA")
23
+ branch = ENV.fetch("GITHUB_REF").gsub("refs/heads/", "")
24
+ feature = ENV.fetch("TEST_FEATURE", "")
25
25
  tag = branch
26
26
 
27
27
  if feature != ''
@@ -29,7 +29,7 @@ PactBroker::Client::PublicationTask.new(:pactflow) do | task |
29
29
  tag = "#{tag}+#{feature}"
30
30
  end
31
31
 
32
- require 'pact_broker/client/version'
32
+ require "pact_broker/client/version"
33
33
  task.auto_detect_version_properties = false
34
34
  task.tags = [tag]
35
35
  task.branch = nil
@@ -38,3 +38,24 @@ PactBroker::Client::PublicationTask.new(:pactflow) do | task |
38
38
  task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
39
39
  task.build_url = PactBroker::Client::Git.build_url
40
40
  end
41
+
42
+ PactBroker::Client::PublicationTask.new(:pactflow_pact_foundation) do | task |
43
+ version = ENV.fetch("GITHUB_SHA")
44
+ branch = ENV.fetch("GITHUB_REF").gsub("refs/heads/", "")
45
+ feature = ENV.fetch("TEST_FEATURE", "")
46
+ tag = branch
47
+
48
+ if feature != ""
49
+ version = "#{version}+#{feature}"
50
+ tag = "#{tag}+#{feature}"
51
+ end
52
+
53
+ require "pact_broker/client/version"
54
+ task.auto_detect_version_properties = false
55
+ task.tags = [tag]
56
+ task.branch = nil
57
+ task.consumer_version = version
58
+ task.pact_broker_base_url = "https://pact-foundation.pactflow.io"
59
+ task.pact_broker_token = ENV["PACT_BROKER_TOKEN_PACT_FOUNDATION"]
60
+ task.build_url = PactBroker::Client::Git.build_url
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.70.0
4
+ version: 1.72.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-29 00:00:00.000000000 Z
11
+ date: 2023-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -106,104 +106,6 @@ dependencies:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
108
  version: '1.0'
109
- - !ruby/object:Gem::Dependency
110
- name: fakefs
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - "~>"
114
- - !ruby/object:Gem::Version
115
- version: '2.4'
116
- type: :development
117
- prerelease: false
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - "~>"
121
- - !ruby/object:Gem::Version
122
- version: '2.4'
123
- - !ruby/object:Gem::Dependency
124
- name: webmock
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '3.0'
130
- type: :development
131
- prerelease: false
132
- version_requirements: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - "~>"
135
- - !ruby/object:Gem::Version
136
- version: '3.0'
137
- - !ruby/object:Gem::Dependency
138
- name: conventional-changelog
139
- requirement: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - "~>"
142
- - !ruby/object:Gem::Version
143
- version: '1.3'
144
- type: :development
145
- prerelease: false
146
- version_requirements: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - "~>"
149
- - !ruby/object:Gem::Version
150
- version: '1.3'
151
- - !ruby/object:Gem::Dependency
152
- name: pact
153
- requirement: !ruby/object:Gem::Requirement
154
- requirements:
155
- - - "~>"
156
- - !ruby/object:Gem::Version
157
- version: '1.16'
158
- type: :development
159
- prerelease: false
160
- version_requirements: !ruby/object:Gem::Requirement
161
- requirements:
162
- - - "~>"
163
- - !ruby/object:Gem::Version
164
- version: '1.16'
165
- - !ruby/object:Gem::Dependency
166
- name: pact-support
167
- requirement: !ruby/object:Gem::Requirement
168
- requirements:
169
- - - "~>"
170
- - !ruby/object:Gem::Version
171
- version: '1.16'
172
- type: :development
173
- prerelease: false
174
- version_requirements: !ruby/object:Gem::Requirement
175
- requirements:
176
- - - "~>"
177
- - !ruby/object:Gem::Version
178
- version: '1.16'
179
- - !ruby/object:Gem::Dependency
180
- name: approvals
181
- requirement: !ruby/object:Gem::Requirement
182
- requirements:
183
- - - '='
184
- - !ruby/object:Gem::Version
185
- version: 0.0.26
186
- type: :development
187
- prerelease: false
188
- version_requirements: !ruby/object:Gem::Requirement
189
- requirements:
190
- - - '='
191
- - !ruby/object:Gem::Version
192
- version: 0.0.26
193
- - !ruby/object:Gem::Dependency
194
- name: rspec-its
195
- requirement: !ruby/object:Gem::Requirement
196
- requirements:
197
- - - "~>"
198
- - !ruby/object:Gem::Version
199
- version: '1.3'
200
- type: :development
201
- prerelease: false
202
- version_requirements: !ruby/object:Gem::Requirement
203
- requirements:
204
- - - "~>"
205
- - !ruby/object:Gem::Version
206
- version: '1.3'
207
109
  description: Client for the Pact Broker. Publish, retrieve and query pacts and verification
208
110
  results. Manage webhooks and environments.
209
111
  email:
@@ -333,10 +235,13 @@ files:
333
235
  - lib/pactflow/client/cli/pactflow.rb
334
236
  - lib/pactflow/client/cli/provider_contract_commands.rb
335
237
  - lib/pactflow/client/provider_contracts/publish.rb
238
+ - lib/pactflow/client/provider_contracts/publish_the_old_way.rb
336
239
  - pact-broker-client.gemspec
337
240
  - script/approve-all.sh
338
241
  - script/can-i-deploy.sh
242
+ - script/ci/record-release.sh
339
243
  - script/create-pacticipant.sh
244
+ - script/foo-bar.json
340
245
  - script/oas.yml
341
246
  - script/publish-pact.sh
342
247
  - script/publish-provider-contract.sh
@@ -354,11 +259,13 @@ files:
354
259
  - spec/fixtures/approvals/describe_environment.approved.txt
355
260
  - spec/fixtures/approvals/describe_pacticipant.approved.txt
356
261
  - spec/fixtures/approvals/list_environments.approved.txt
262
+ - spec/fixtures/approvals/publish_provider_contract.approved.txt
357
263
  - spec/fixtures/foo-bar.json
358
264
  - spec/integration/can_i_deploy_spec.rb
359
265
  - spec/integration/can_i_merge_spec.rb
360
266
  - spec/integration/create_version_tag_spec.rb
361
267
  - spec/integration/describe_environment_spec.rb
268
+ - spec/integration/publish_provider_contract_spec.rb
362
269
  - spec/lib/pact_broker/client/base_client_spec.rb
363
270
  - spec/lib/pact_broker/client/can_i_deploy_spec.rb
364
271
  - spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
@@ -395,6 +302,7 @@ files:
395
302
  - spec/lib/pact_broker/client/versions/describe_spec.rb
396
303
  - spec/lib/pact_broker/client/versions_spec.rb
397
304
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
305
+ - spec/lib/pactflow/client/provider_contracts/publish_spec.rb
398
306
  - spec/pacts/pact_broker_client-pact_broker.json
399
307
  - spec/pacts/pact_broker_client-pactflow.json
400
308
  - spec/readme_spec.rb
@@ -413,6 +321,7 @@ files:
413
321
  - spec/service_providers/pact_broker_client_versions_spec.rb
414
322
  - spec/service_providers/pact_helper.rb
415
323
  - spec/service_providers/pactflow_publish_provider_contract_spec.rb
324
+ - spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb
416
325
  - spec/service_providers/pactflow_webhooks_create_spec.rb
417
326
  - spec/service_providers/pacticipants_create_spec.rb
418
327
  - spec/service_providers/publish_pacts_spec.rb
@@ -464,11 +373,13 @@ test_files:
464
373
  - spec/fixtures/approvals/describe_environment.approved.txt
465
374
  - spec/fixtures/approvals/describe_pacticipant.approved.txt
466
375
  - spec/fixtures/approvals/list_environments.approved.txt
376
+ - spec/fixtures/approvals/publish_provider_contract.approved.txt
467
377
  - spec/fixtures/foo-bar.json
468
378
  - spec/integration/can_i_deploy_spec.rb
469
379
  - spec/integration/can_i_merge_spec.rb
470
380
  - spec/integration/create_version_tag_spec.rb
471
381
  - spec/integration/describe_environment_spec.rb
382
+ - spec/integration/publish_provider_contract_spec.rb
472
383
  - spec/lib/pact_broker/client/base_client_spec.rb
473
384
  - spec/lib/pact_broker/client/can_i_deploy_spec.rb
474
385
  - spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
@@ -505,6 +416,7 @@ test_files:
505
416
  - spec/lib/pact_broker/client/versions/describe_spec.rb
506
417
  - spec/lib/pact_broker/client/versions_spec.rb
507
418
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
419
+ - spec/lib/pactflow/client/provider_contracts/publish_spec.rb
508
420
  - spec/pacts/pact_broker_client-pact_broker.json
509
421
  - spec/pacts/pact_broker_client-pactflow.json
510
422
  - spec/readme_spec.rb
@@ -523,6 +435,7 @@ test_files:
523
435
  - spec/service_providers/pact_broker_client_versions_spec.rb
524
436
  - spec/service_providers/pact_helper.rb
525
437
  - spec/service_providers/pactflow_publish_provider_contract_spec.rb
438
+ - spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb
526
439
  - spec/service_providers/pactflow_webhooks_create_spec.rb
527
440
  - spec/service_providers/pacticipants_create_spec.rb
528
441
  - spec/service_providers/publish_pacts_spec.rb