pact_broker-client 1.70.0 → 1.71.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,13 @@
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
+ allow(ENV).to receive(:fetch).and_call_original
10
+ allow(ENV).to receive(:fetch).with("PACT_BROKER_FEATURES", "").and_return("publish_provider_contracts_all_in_one")
9
11
  end
10
12
 
11
13
  include_context "pact broker"
@@ -17,8 +19,9 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
17
19
  provider_version_number: "1",
18
20
  branch_name: "main",
19
21
  tags: ["dev"],
22
+ build_url: "http://build",
20
23
  contract: {
21
- content: { some: "contract" }.to_yaml,
24
+ content: { "some" => "contract" }.to_yaml,
22
25
  content_type: "application/yaml",
23
26
  specification: "oas"
24
27
  },
@@ -33,14 +36,17 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
33
36
  }
34
37
  end
35
38
 
36
- let(:body) { { some: "body" }.to_json }
37
-
38
39
  let(:request_body) do
39
40
  {
40
- "content" => "LS0tCjpzb21lOiBjb250cmFjdAo=",
41
- "contractType" => "oas",
41
+ "pacticipantVersionNumber" => "1",
42
+ "tags" => ["dev"],
43
+ "branch" => "main",
44
+ "buildUrl" => "http://build",
45
+ "contract" => {
46
+ "content" => "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
42
47
  "contentType" => "application/yaml",
43
- "verificationResults" => {
48
+ "specification" => "oas",
49
+ "selfVerificationResults" => {
44
50
  "success" => true,
45
51
  "content" => "c29tZSByZXN1bHRz",
46
52
  "contentType" => "text/plain",
@@ -48,14 +54,36 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
48
54
  "verifier" => "my custom tool",
49
55
  "verifierVersion" => "1.0"
50
56
  }
57
+ }
51
58
  }
52
59
  end
53
60
 
54
- let(:response_status) { 201 }
61
+ let(:response_status) { 200 }
62
+
63
+ # Can't tell from the response if the buildUrl was correct, but it's not that important
64
+ # Add some assertions to the body to ensure we have called the endpoint correctly,
65
+ # not because we use the properties in the CLI output.
66
+ # There is unfortunately no good way to determine from the response whether or not
67
+ # we have correctly published the self verification results.
55
68
  let(:success_response) do
56
69
  {
57
70
  status: response_status,
58
- headers: pact_broker_response_headers
71
+ headers: pact_broker_response_headers,
72
+ body: {
73
+ "notices" => Pact.each_like("text" => "some notice", "type" => "info"),
74
+ "_embedded" => {
75
+ "version" => {
76
+ # This tells us we have set the version number correctly
77
+ "number" => "1"
78
+ }
79
+ },
80
+ "_links" => {
81
+ # The links tell us we have successfully created the tags, but we don't care about the contents
82
+ "pb:pacticipant-version-tags" => [{}],
83
+ # The link tells us we have successfully created the branch version, but we don't care about the contents
84
+ "pb:branch-version" => {},
85
+ }
86
+ }
59
87
  }
60
88
  end
61
89
 
@@ -74,54 +102,38 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
74
102
  context "creating a provider contract with valid parameters" do
75
103
  before do
76
104
  pactflow
77
- .upon_receiving("a request to create a provider contract")
105
+ .given("the pb:publish-provider-contract relation exists in the index resource")
106
+ .upon_receiving("a request for the index resource")
78
107
  .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"
108
+ method: "GET",
109
+ path: "/",
110
+ headers: get_request_headers
111
+ ).will_respond_with(
112
+ status: 200,
113
+ headers: pact_broker_response_headers,
114
+ body: {
115
+ _links: {
116
+ :'pf:publish-provider-contract' => {
117
+ href: placeholder_url_term("pf:publish-provider-contract", ['provider'], pactflow)
118
+ }
119
+ }
102
120
  }
103
- } }
104
- }
105
- end
106
- before do
121
+ )
122
+
107
123
  pactflow
108
- .given("there is a pf:ui href in the response")
109
- .upon_receiving("a request to create a provider contract")
124
+ .upon_receiving("a request to publish a provider contract")
110
125
  .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)
126
+ method: :post,
127
+ path: placeholder_path("pf:publish-provider-contract", ["Bar"]),
128
+ headers: post_request_headers,
129
+ body: request_body
130
+ ).will_respond_with(success_response)
117
131
  end
118
132
 
119
- it "returns a CommandResult with success = true and a provider contract ui url" do
133
+ it "returns a CommandResult with success = true" do
120
134
  expect(subject).to be_a PactBroker::Client::CommandResult
121
135
  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]
136
+ expect(subject.message).to include "some notice"
125
137
  end
126
138
  end
127
- end
139
+ 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.71.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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -333,10 +333,12 @@ files:
333
333
  - lib/pactflow/client/cli/pactflow.rb
334
334
  - lib/pactflow/client/cli/provider_contract_commands.rb
335
335
  - lib/pactflow/client/provider_contracts/publish.rb
336
+ - lib/pactflow/client/provider_contracts/publish_the_old_way.rb
336
337
  - pact-broker-client.gemspec
337
338
  - script/approve-all.sh
338
339
  - script/can-i-deploy.sh
339
340
  - script/create-pacticipant.sh
341
+ - script/foo-bar.json
340
342
  - script/oas.yml
341
343
  - script/publish-pact.sh
342
344
  - script/publish-provider-contract.sh
@@ -354,11 +356,13 @@ files:
354
356
  - spec/fixtures/approvals/describe_environment.approved.txt
355
357
  - spec/fixtures/approvals/describe_pacticipant.approved.txt
356
358
  - spec/fixtures/approvals/list_environments.approved.txt
359
+ - spec/fixtures/approvals/publish_provider_contract.approved.txt
357
360
  - spec/fixtures/foo-bar.json
358
361
  - spec/integration/can_i_deploy_spec.rb
359
362
  - spec/integration/can_i_merge_spec.rb
360
363
  - spec/integration/create_version_tag_spec.rb
361
364
  - spec/integration/describe_environment_spec.rb
365
+ - spec/integration/publish_provider_contract_spec.rb
362
366
  - spec/lib/pact_broker/client/base_client_spec.rb
363
367
  - spec/lib/pact_broker/client/can_i_deploy_spec.rb
364
368
  - spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
@@ -395,6 +399,7 @@ files:
395
399
  - spec/lib/pact_broker/client/versions/describe_spec.rb
396
400
  - spec/lib/pact_broker/client/versions_spec.rb
397
401
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
402
+ - spec/lib/pactflow/client/provider_contracts/publish_spec.rb
398
403
  - spec/pacts/pact_broker_client-pact_broker.json
399
404
  - spec/pacts/pact_broker_client-pactflow.json
400
405
  - spec/readme_spec.rb
@@ -413,6 +418,7 @@ files:
413
418
  - spec/service_providers/pact_broker_client_versions_spec.rb
414
419
  - spec/service_providers/pact_helper.rb
415
420
  - spec/service_providers/pactflow_publish_provider_contract_spec.rb
421
+ - spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb
416
422
  - spec/service_providers/pactflow_webhooks_create_spec.rb
417
423
  - spec/service_providers/pacticipants_create_spec.rb
418
424
  - spec/service_providers/publish_pacts_spec.rb
@@ -464,11 +470,13 @@ test_files:
464
470
  - spec/fixtures/approvals/describe_environment.approved.txt
465
471
  - spec/fixtures/approvals/describe_pacticipant.approved.txt
466
472
  - spec/fixtures/approvals/list_environments.approved.txt
473
+ - spec/fixtures/approvals/publish_provider_contract.approved.txt
467
474
  - spec/fixtures/foo-bar.json
468
475
  - spec/integration/can_i_deploy_spec.rb
469
476
  - spec/integration/can_i_merge_spec.rb
470
477
  - spec/integration/create_version_tag_spec.rb
471
478
  - spec/integration/describe_environment_spec.rb
479
+ - spec/integration/publish_provider_contract_spec.rb
472
480
  - spec/lib/pact_broker/client/base_client_spec.rb
473
481
  - spec/lib/pact_broker/client/can_i_deploy_spec.rb
474
482
  - spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
@@ -505,6 +513,7 @@ test_files:
505
513
  - spec/lib/pact_broker/client/versions/describe_spec.rb
506
514
  - spec/lib/pact_broker/client/versions_spec.rb
507
515
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
516
+ - spec/lib/pactflow/client/provider_contracts/publish_spec.rb
508
517
  - spec/pacts/pact_broker_client-pact_broker.json
509
518
  - spec/pacts/pact_broker_client-pactflow.json
510
519
  - spec/readme_spec.rb
@@ -523,6 +532,7 @@ test_files:
523
532
  - spec/service_providers/pact_broker_client_versions_spec.rb
524
533
  - spec/service_providers/pact_helper.rb
525
534
  - spec/service_providers/pactflow_publish_provider_contract_spec.rb
535
+ - spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb
526
536
  - spec/service_providers/pactflow_webhooks_create_spec.rb
527
537
  - spec/service_providers/pacticipants_create_spec.rb
528
538
  - spec/service_providers/publish_pacts_spec.rb