pact_broker-client 1.38.3 → 1.43.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +47 -0
  4. data/Gemfile +4 -0
  5. data/README.md +57 -18
  6. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +182 -2
  7. data/example/scripts/publish-pact.sh +1 -1
  8. data/lib/pact_broker/client/backports.rb +9 -0
  9. data/lib/pact_broker/client/base_command.rb +95 -0
  10. data/lib/pact_broker/client/can_i_deploy.rb +20 -3
  11. data/lib/pact_broker/client/cli/broker.rb +41 -28
  12. data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
  13. data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
  14. data/lib/pact_broker/client/cli/pacticipant_commands.rb +44 -0
  15. data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -0
  16. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
  17. data/lib/pact_broker/client/colorize_notices.rb +31 -0
  18. data/lib/pact_broker/client/environments.rb +3 -0
  19. data/lib/pact_broker/client/environments/create_environment.rb +31 -0
  20. data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
  21. data/lib/pact_broker/client/environments/describe_environment.rb +36 -0
  22. data/lib/pact_broker/client/environments/environment_command.rb +66 -0
  23. data/lib/pact_broker/client/environments/list_environments.rb +30 -0
  24. data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
  25. data/lib/pact_broker/client/environments/update_environment.rb +31 -0
  26. data/lib/pact_broker/client/generate_display_name.rb +27 -0
  27. data/lib/pact_broker/client/hal/entity.rb +26 -3
  28. data/lib/pact_broker/client/hal/http_client.rb +11 -2
  29. data/lib/pact_broker/client/hal/link.rb +20 -0
  30. data/lib/pact_broker/client/hal/links.rb +15 -0
  31. data/lib/pact_broker/client/hal_client_methods.rb +9 -3
  32. data/lib/pact_broker/client/matrix.rb +4 -0
  33. data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
  34. data/lib/pact_broker/client/matrix/resource.rb +26 -1
  35. data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
  36. data/lib/pact_broker/client/pacticipants.rb +6 -0
  37. data/lib/pact_broker/client/pacticipants/create.rb +24 -34
  38. data/lib/pact_broker/client/pacticipants/list.rb +34 -0
  39. data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
  40. data/lib/pact_broker/client/pacts.rb +0 -1
  41. data/lib/pact_broker/client/publish_pacts.rb +94 -128
  42. data/lib/pact_broker/client/publish_pacts_the_old_way.rb +194 -0
  43. data/lib/pact_broker/client/string_refinements.rb +56 -0
  44. data/lib/pact_broker/client/tasks/publication_task.rb +3 -3
  45. data/lib/pact_broker/client/version.rb +1 -1
  46. data/lib/pact_broker/client/versions/record_deployment.rb +14 -38
  47. data/lib/pact_broker/client/versions/record_undeployment.rb +45 -68
  48. data/pact-broker-client.gemspec +2 -0
  49. data/script/approve-all.sh +6 -0
  50. data/script/publish-pact.sh +36 -5
  51. data/script/record-deployment.sh +1 -3
  52. data/script/record-undeployment.sh +4 -0
  53. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
  54. data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
  55. data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
  56. data/spec/fixtures/foo-bar.json +31 -0
  57. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +47 -5
  58. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +5 -5
  59. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +36 -7
  60. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
  61. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
  62. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
  63. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
  64. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
  65. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
  66. data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
  67. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +5 -2
  68. data/spec/lib/pact_broker/client/{publish_pacts_spec.rb → publish_pacts_the_old_way_spec.rb} +10 -9
  69. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +18 -12
  70. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +17 -24
  71. data/spec/pacts/pact_broker_client-pact_broker.json +197 -2
  72. data/spec/service_providers/create_environment_spec.rb +78 -0
  73. data/spec/service_providers/list_environments_spec.rb +77 -0
  74. data/spec/service_providers/pact_broker_client_create_version_spec.rb +4 -4
  75. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
  76. data/spec/service_providers/pacticipants_create_spec.rb +5 -4
  77. data/spec/service_providers/publish_pacts_spec.rb +116 -0
  78. data/spec/service_providers/record_deployment_spec.rb +14 -11
  79. data/spec/spec_helper.rb +3 -1
  80. data/spec/support/approvals.rb +26 -0
  81. data/spec/support/shared_context.rb +6 -2
  82. metadata +86 -5
@@ -48,6 +48,27 @@ module PactBroker
48
48
  ],[
49
49
  ["--pacticipant", "Foo=Bar", "--version", "1.2.3"],
50
50
  [{ pacticipant: "Foo=Bar", version: "1.2.3" } ]
51
+ ],[
52
+ ["--ignore", "Foo", "--version", "1.2.3"],
53
+ [{ pacticipant: "Foo", version: "1.2.3", ignore: true }]
54
+ ],[
55
+ ["--ignore", "Foo", "--ignore", "Bar", "--version", "1.2.3"],
56
+ [{ pacticipant: "Foo", ignore: true }, { pacticipant: "Bar", version: "1.2.3", ignore: true }]
57
+ ],[
58
+ ["--ignore", "Foo", "--pacticipant", "Bar", "--version", "1.2.3"],
59
+ [{ pacticipant: "Foo", ignore: true }, { pacticipant: "Bar", version: "1.2.3" }]
60
+ ],[
61
+ ["--pacticipant", "Foo", "--version", "1", "--version", "2"],
62
+ [{ pacticipant: "Foo", version: "2" }]
63
+ ],[
64
+ ["--pacticipant", "Foo", "--version", "2", "--latest"],
65
+ [{ pacticipant: "Foo", version: "2", latest: true }]
66
+ ],[
67
+ ["--pacticipant", "Foo", "--version", "2", "--latest", "--latest"],
68
+ [{ pacticipant: "Foo", version: "2", latest: true }]
69
+ ],[
70
+ ["--version", "2"],
71
+ [{ pacticipant: nil, version: "2" }]
51
72
  ]
52
73
  ]
53
74
 
@@ -0,0 +1,120 @@
1
+ require 'pact_broker/client/environments/delete_environment'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Environments
6
+ describe DeleteEnvironment do
7
+ before do
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
+ end
11
+
12
+ let(:params) do
13
+ {
14
+ uuid: uuid,
15
+ name: "new name",
16
+ displayName: "new display name",
17
+ production: false,
18
+ output: output
19
+ }
20
+ end
21
+ let(:options) do
22
+ {
23
+ output: output,
24
+ verbose: verbose
25
+ }
26
+ end
27
+ let(:uuid) { "a9aa4c22-66bb-45d3-ba4c-4916ac8b48c5" }
28
+ let(:pact_broker_base_url) { "http://example.org" }
29
+ let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
30
+ let(:response_headers) { { "Content-Type" => "application/hal+json"} }
31
+ let(:output) { "text" }
32
+ let(:verbose) { false }
33
+
34
+ before do
35
+ stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
36
+ stub_request(:get, "http://example.org/environments/#{uuid}").to_return(status: get_environment_response_status, body: get_environment_response_body, headers: response_headers)
37
+ stub_request(:delete, "http://example.org/environments/#{uuid}").to_return(status: delete_response_status, body: delete_environment_response_body, headers: response_headers)
38
+ end
39
+ let(:delete_response_status) { 200 }
40
+ let(:get_environment_response_status) { 200 }
41
+
42
+ let(:index_response_body) do
43
+ {
44
+ "_links" => {
45
+ "pb:environments" => {},
46
+ "pb:environment" => {
47
+ "href" => "http://example.org/environments/{uuid}"
48
+ }
49
+ }
50
+ }.to_json
51
+ end
52
+
53
+ let(:get_environment_response_body) do
54
+ {
55
+ name: "existing name",
56
+ displayName: "existing display name",
57
+ production: true
58
+ }.to_json
59
+ end
60
+
61
+ let(:delete_environment_response_body) do
62
+ JSON.parse(get_environment_response_body).merge("updatedAt" => "2021-05-28T13:34:54+10:00").to_json
63
+ end
64
+
65
+ subject { DeleteEnvironment.call(params, options, pact_broker_client_options) }
66
+
67
+ context "when delete is successful" do
68
+ its(:success) { is_expected.to be true }
69
+ its(:message) { is_expected.to include "Deleted environment existing name from the Pact Broker" }
70
+
71
+ context "when output is json" do
72
+ let(:output) { "json" }
73
+
74
+ its(:message) { is_expected.to eq delete_environment_response_body }
75
+ end
76
+ end
77
+
78
+ context "when environments are not supported" do
79
+ let(:index_response_body) { "{}" }
80
+
81
+ its(:success) { is_expected.to be false }
82
+ its(:message) { is_expected.to include "does not support environments" }
83
+ end
84
+
85
+ context "when the environment does not exist" do
86
+ let(:get_environment_response_status) { 404 }
87
+ let(:get_environment_response_body) { "" }
88
+ let(:delete_environment_response_body) { "" }
89
+
90
+ its(:success) { is_expected.to be false }
91
+ its(:message) { is_expected.to include get_environment_response_body }
92
+
93
+ context "when output is json" do
94
+ let(:output) { "json" }
95
+
96
+ its(:message) { is_expected.to eq "{}" }
97
+ end
98
+ end
99
+
100
+ context "when delete is unsuccessful" do
101
+ let(:delete_response_status) { 500 }
102
+ let(:delete_environment_response_body) do
103
+ {
104
+ "some" => "error"
105
+ }.to_json
106
+ end
107
+
108
+ its(:success) { is_expected.to be false }
109
+ its(:message) { is_expected.to include delete_environment_response_body }
110
+
111
+ context "when output is json" do
112
+ let(:output) { "json" }
113
+
114
+ its(:message) { is_expected.to eq delete_environment_response_body }
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,89 @@
1
+ require 'pact_broker/client/environments/describe_environment'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Environments
6
+ describe DescribeEnvironment do
7
+ before do
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
+ end
11
+
12
+ let(:params) { { uuid: uuid } }
13
+ let(:options) { { output: output }}
14
+ let(:uuid) { "a9aa4c22-66bb-45d3-ba4c-4916ac8b48c5" }
15
+ let(:pact_broker_base_url) { "http://example.org" }
16
+ let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
17
+ let(:response_headers) { { "Content-Type" => "application/hal+json"} }
18
+ let(:output) { "text" }
19
+
20
+ before do
21
+ stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
22
+ stub_request(:get, "http://example.org/environments/#{uuid}").to_return(status: get_environment_response_status, body: get_environment_response_body, headers: response_headers)
23
+ end
24
+
25
+ let(:get_environment_response_status) { 200 }
26
+ let(:index_response_body) do
27
+ {
28
+ "_links" => {
29
+ "pb:environments" => {},
30
+ "pb:environment" => {
31
+ "href" => "http://example.org/environments/{uuid}"
32
+ }
33
+ }
34
+ }.to_json
35
+ end
36
+
37
+ let(:get_environment_response_body) do
38
+ {
39
+ name: "existing name",
40
+ displayName: "existing display name",
41
+ production: true,
42
+ contacts: [
43
+ name: "Someone",
44
+ details: { emailAddress: "foo@bar.com" }
45
+ ]
46
+ }.to_json
47
+ end
48
+
49
+ subject { DescribeEnvironment.call(params, options, pact_broker_client_options) }
50
+
51
+ context "when the environment exists" do
52
+ its(:success) { is_expected.to be true }
53
+
54
+ it "describes the environment" do
55
+ Approvals.verify(subject.message, :name => "describe_environment", format: :txt)
56
+ end
57
+
58
+ context "when output is json" do
59
+ let(:output) { "json" }
60
+
61
+ its(:message) { is_expected.to eq get_environment_response_body }
62
+ end
63
+ end
64
+
65
+ context "when environments are not supported" do
66
+ let(:index_response_body) { "{}" }
67
+
68
+ its(:success) { is_expected.to be false }
69
+ its(:message) { is_expected.to include "does not support environments" }
70
+ end
71
+
72
+ context "when the environment does not exist" do
73
+ let(:get_environment_response_status) { 404 }
74
+ let(:get_environment_response_body) { "" }
75
+ let(:put_environment_response_body) { "" }
76
+
77
+ its(:success) { is_expected.to be false }
78
+ its(:message) { is_expected.to include get_environment_response_body }
79
+
80
+ context "when output is json" do
81
+ let(:output) { "json" }
82
+
83
+ its(:message) { is_expected.to eq "{}" }
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,167 @@
1
+ require 'pact_broker/client/environments/update_environment'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Environments
6
+ describe UpdateEnvironment do
7
+ before do
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
+ end
11
+
12
+ let(:params) do
13
+ {
14
+ uuid: uuid,
15
+ name: "new name",
16
+ display_name: "new display name",
17
+ production: false
18
+ }
19
+ end
20
+ let(:options) do
21
+ {
22
+ output: output,
23
+ verbose: verbose
24
+ }
25
+ end
26
+ let(:uuid) { "a9aa4c22-66bb-45d3-ba4c-4916ac8b48c5" }
27
+ let(:pact_broker_base_url) { "http://example.org" }
28
+ let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
29
+ let(:response_headers) { { "Content-Type" => "application/hal+json"} }
30
+ let(:output) { "text" }
31
+ let(:verbose) { false }
32
+
33
+ before do
34
+ stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
35
+ stub_request(:get, "http://example.org/environments/#{uuid}").to_return(status: get_environment_response_status, body: get_environment_response_body, headers: response_headers)
36
+ stub_request(:put, "http://example.org/environments/#{uuid}").to_return(status: put_response_status, body: put_environment_response_body, headers: response_headers)
37
+ end
38
+ let(:put_response_status) { 200 }
39
+ let(:get_environment_response_status) { 200 }
40
+ let(:put_request_body) do
41
+ {
42
+ name: "new name",
43
+ displayName: "new display name",
44
+ production: false
45
+ }.to_json
46
+ end
47
+
48
+ let(:index_response_body) do
49
+ {
50
+ "_links" => {
51
+ "pb:environments" => {},
52
+ "pb:environment" => {
53
+ "href" => "http://example.org/environments/{uuid}"
54
+ }
55
+ }
56
+ }.to_json
57
+ end
58
+
59
+ let(:get_environment_response_body) do
60
+ {
61
+ name: "existing name",
62
+ displayName: "existing display name",
63
+ production: true
64
+ }.to_json
65
+ end
66
+
67
+ let(:put_environment_response_body) do
68
+ JSON.parse(get_environment_response_body).merge("updatedAt" => "2021-05-28T13:34:54+10:00").to_json
69
+ end
70
+
71
+ subject { UpdateEnvironment.call(params, options, pact_broker_client_options) }
72
+
73
+ it "updates the environment" do
74
+ request = stub_request(:put, "http://example.org/environments/#{uuid}").with(body: put_request_body)
75
+ subject
76
+ expect(request).to have_been_made
77
+ end
78
+
79
+ context "when update is successful" do
80
+ its(:success) { is_expected.to be true }
81
+ its(:message) { is_expected.to include "Updated new name environment in the Pact Broker" }
82
+
83
+ context "when output is json" do
84
+ let(:output) { "json" }
85
+
86
+ its(:message) { is_expected.to eq put_environment_response_body }
87
+ end
88
+ end
89
+
90
+ context "when environments are not supported" do
91
+ let(:index_response_body) { "{}" }
92
+
93
+ its(:success) { is_expected.to be false }
94
+ its(:message) { is_expected.to include "does not support environments" }
95
+ end
96
+
97
+ context "when a StandardError occurs" do
98
+ before do
99
+ allow_any_instance_of(described_class).to receive(:do_call).and_raise(StandardError.new("Foo"))
100
+ end
101
+
102
+ its(:success) { is_expected.to be false }
103
+ its(:message) { is_expected.to include "StandardError - Foo" }
104
+
105
+ context "when verbose is on" do
106
+ let(:verbose) { true }
107
+
108
+ it "includes the message and class and backtrace in the error" do
109
+ expect(subject.message.split("\n").size).to be > 2
110
+ end
111
+ end
112
+
113
+ context "when output is json" do
114
+ let(:output) { "json" }
115
+
116
+ it "includes the message and class in the error" do
117
+ message_hash = JSON.parse(subject.message)
118
+ expect(message_hash).to eq "error" => { "message" => "Foo", "class" => "StandardError" }
119
+ end
120
+
121
+ context "when verbose is on" do
122
+ let(:verbose) { true }
123
+
124
+ it "includes the message and class and backtrace in the error" do
125
+ message_hash = JSON.parse(subject.message)
126
+ expect(message_hash["error"]["backtrace"]).to be_a(Array)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ context "when the environment does not exist" do
133
+ let(:get_environment_response_status) { 404 }
134
+ let(:get_environment_response_body) { "" }
135
+ let(:put_environment_response_body) { "" }
136
+
137
+ its(:success) { is_expected.to be false }
138
+ its(:message) { is_expected.to include get_environment_response_body }
139
+
140
+ context "when output is json" do
141
+ let(:output) { "json" }
142
+
143
+ its(:message) { is_expected.to eq "{}" }
144
+ end
145
+ end
146
+
147
+ context "when update is unsuccessful" do
148
+ let(:put_response_status) { 400 }
149
+ let(:put_environment_response_body) do
150
+ {
151
+ "some" => "error"
152
+ }.to_json
153
+ end
154
+
155
+ its(:success) { is_expected.to be false }
156
+ its(:message) { is_expected.to include put_environment_response_body }
157
+
158
+ context "when output is json" do
159
+ let(:output) { "json" }
160
+
161
+ its(:message) { is_expected.to eq put_environment_response_body }
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,39 @@
1
+ require 'pact_broker/client/generate_display_name'
2
+
3
+ module PactBroker
4
+ module Client
5
+ describe GenerateDisplayName do
6
+ describe ".call" do
7
+ TEST_CASES = {
8
+ "foo" => "Foo",
9
+ "MyService" => "My Service",
10
+ "my-service" => "My Service",
11
+ "my_service" => "My Service",
12
+ "my service" => "My Service",
13
+ "ABCService" => "ABC Service",
14
+ "A4Service" => "A4 Service",
15
+ "SNSPactEventConsumer" => "SNS Pact Event Consumer",
16
+ "AWSSummiteerWeb" => "AWS Summiteer Web",
17
+ "Beer-Consumer" => "Beer Consumer",
18
+ "foo.pretend-consumer" => "Foo Pretend Consumer",
19
+ "Client-XX" => "Client XX",
20
+ "providerJSWorkshop" => "Provider JS Workshop",
21
+ "e2e Provider Example" => "E2e Provider Example",
22
+ "MP - Our Provider" => "MP - Our Provider",
23
+ "PoC - Pact-broker-consumer" => "PoC - Pact Broker Consumer",
24
+ "QB-DATABASE Service" => "QB DATABASE Service",
25
+ "Support Species App (Provider)" => "Support Species App (Provider)",
26
+ 9 => "9",
27
+ "" => "",
28
+ nil => nil
29
+ }
30
+
31
+ TEST_CASES.each do | name, expected_display_name |
32
+ it "converts #{name.inspect} to #{expected_display_name.inspect}" do
33
+ expect(GenerateDisplayName.call(name)).to eq expected_display_name
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -73,7 +73,7 @@ module PactBroker::Client
73
73
  subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client) }
74
74
 
75
75
  it "raises an error" do
76
- expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error retrieving http://pact status="
76
+ expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error making request to http://pact status="
77
77
  end
78
78
  end
79
79
 
@@ -83,7 +83,7 @@ module PactBroker::Client
83
83
  subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client, response) }
84
84
 
85
85
  it "raises an error" do
86
- expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error retrieving http://pact status=200 body"
86
+ expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error making request to http://pact status=200 body"
87
87
  end
88
88
  end
89
89
  end