pact_broker-client 1.41.0 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/lib/pact_broker/client/backports.rb +9 -0
- data/lib/pact_broker/client/base_command.rb +95 -0
- data/lib/pact_broker/client/cli/broker.rb +11 -19
- data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
- data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
- data/lib/pact_broker/client/cli/pacticipant_commands.rb +44 -0
- data/lib/pact_broker/client/environments.rb +3 -0
- data/lib/pact_broker/client/environments/create_environment.rb +31 -0
- data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
- data/lib/pact_broker/client/environments/describe_environment.rb +36 -0
- data/lib/pact_broker/client/environments/environment_command.rb +66 -0
- data/lib/pact_broker/client/environments/list_environments.rb +30 -0
- data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
- data/lib/pact_broker/client/environments/update_environment.rb +31 -0
- data/lib/pact_broker/client/generate_display_name.rb +27 -0
- data/lib/pact_broker/client/hal/entity.rb +10 -3
- data/lib/pact_broker/client/hal/http_client.rb +5 -0
- data/lib/pact_broker/client/hal/link.rb +8 -0
- data/lib/pact_broker/client/hal_client_methods.rb +1 -3
- data/lib/pact_broker/client/matrix/text_formatter.rb +21 -13
- data/lib/pact_broker/client/pacticipants.rb +6 -0
- data/lib/pact_broker/client/pacticipants/create.rb +24 -34
- data/lib/pact_broker/client/pacticipants/list.rb +34 -0
- data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
- data/lib/pact_broker/client/string_refinements.rb +56 -0
- data/lib/pact_broker/client/version.rb +1 -1
- data/pact-broker-client.gemspec +1 -0
- data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
- data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +3 -3
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
- data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
- data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
- data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
- data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +2 -2
- data/spec/service_providers/create_environment_spec.rb +78 -0
- data/spec/service_providers/list_environments_spec.rb +77 -0
- data/spec/service_providers/pacticipants_create_spec.rb +5 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/support/approvals.rb +1 -1
- metadata +48 -3
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'table_print'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Client
|
6
|
+
module Pacticipants2
|
7
|
+
class TextFormatter
|
8
|
+
def self.call(pacticipants)
|
9
|
+
return "" if pacticipants.size == 0
|
10
|
+
|
11
|
+
data = pacticipants.collect do | pacticipant |
|
12
|
+
# Might add a UUID in at some stage. Backwards compatible supporting code.
|
13
|
+
OpenStruct.new({ uuid: "" }.merge(pacticipant).merge(url: pacticipant["_links"]["self"]["href"]))
|
14
|
+
end.sort_by{ | pacticipant | pacticipant.name.downcase }
|
15
|
+
|
16
|
+
TablePrint::Printer.new(data, tp_options(data)).table_print
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.tp_options(data)
|
20
|
+
uuid_width = max_width(data, :uuid, "")
|
21
|
+
name_width = max_width(data, :name, "NAME")
|
22
|
+
display_name_width = max_width(data, :displayName, "DISPLAY NAME")
|
23
|
+
|
24
|
+
tp_options = [
|
25
|
+
{ name: { width: name_width} },
|
26
|
+
{ displayName: { display_name: "Display name", width: display_name_width } },
|
27
|
+
]
|
28
|
+
|
29
|
+
if uuid_width > 0
|
30
|
+
tp_options.unshift({ uuid: { width: uuid_width } })
|
31
|
+
end
|
32
|
+
tp_options
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.max_width(data, column, title)
|
36
|
+
(data.collect{ |row| row.send(column) } + [title]).compact.collect(&:size).max
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module StringRefinements
|
4
|
+
refine NilClass do
|
5
|
+
def blank?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
refine String do
|
11
|
+
def not_blank?
|
12
|
+
!blank?
|
13
|
+
end
|
14
|
+
|
15
|
+
def blank?
|
16
|
+
self.strip.size == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
# ripped from rubyworks/facets, thank you
|
20
|
+
def snakecase
|
21
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
22
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
23
|
+
.tr('-', '_')
|
24
|
+
.gsub(/\s/, '_')
|
25
|
+
.gsub(/__+/, '_')
|
26
|
+
.downcase
|
27
|
+
end
|
28
|
+
|
29
|
+
# ripped from rubyworks/facets, thank you
|
30
|
+
def camelcase(*separators)
|
31
|
+
case separators.first
|
32
|
+
when Symbol, TrueClass, FalseClass, NilClass
|
33
|
+
first_letter = separators.shift
|
34
|
+
end
|
35
|
+
|
36
|
+
separators = ['_', '\s'] if separators.empty?
|
37
|
+
|
38
|
+
str = self.dup
|
39
|
+
|
40
|
+
separators.each do |s|
|
41
|
+
str = str.gsub(/(?:#{s}+)([a-z])/){ $1.upcase }
|
42
|
+
end
|
43
|
+
|
44
|
+
case first_letter
|
45
|
+
when :upper, true
|
46
|
+
str = str.gsub(/(\A|\s)([a-z])/){ $1 + $2.upcase }
|
47
|
+
when :lower, false
|
48
|
+
str = str.gsub(/(\A|\s)([A-Z])/){ $1 + $2.downcase }
|
49
|
+
end
|
50
|
+
|
51
|
+
str
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/pact-broker-client.gemspec
CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |gem|
|
|
34
34
|
gem.add_development_dependency 'pact', '~> 1.16'
|
35
35
|
gem.add_development_dependency 'pact-support', '~> 1.16'
|
36
36
|
gem.add_development_dependency 'approvals', '>=0.0.24', '<1.0.0'
|
37
|
+
gem.add_development_dependency 'rspec-its', '~> 1.3'
|
37
38
|
end
|
@@ -37,7 +37,7 @@ module PactBroker
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "invokes the CanIDeploy service" do
|
40
|
-
expect(CanIDeploy).to receive(:call).with('http://pact-broker', version_selectors, {to_tag: nil, to_environment: nil, limit: 1000, ignore_selectors: []}, {output: 'table', retry_while_unknown: 1, retry_interval: 2}, {verbose: 'verbose'})
|
40
|
+
expect(CanIDeploy).to receive(:call).with('http://pact-broker', version_selectors, { to_tag: nil, to_environment: nil, limit: 1000, ignore_selectors: []}, {output: 'table', retry_while_unknown: 1, retry_interval: 2}, { pact_broker_base_url: 'http://pact-broker', verbose: 'verbose' })
|
41
41
|
invoke_can_i_deploy
|
42
42
|
end
|
43
43
|
|
@@ -78,7 +78,7 @@ module PactBroker
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it "invokes the CanIDeploy service with the basic auth credentials" do
|
81
|
-
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {basic_auth: {username: "foo", password: "bar"}, verbose: 'verbose'})
|
81
|
+
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, { pact_broker_base_url: 'http://pact-broker', basic_auth: {username: "foo", password: "bar"}, verbose: 'verbose'})
|
82
82
|
invoke_can_i_deploy
|
83
83
|
end
|
84
84
|
end
|
@@ -89,7 +89,7 @@ module PactBroker
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it "invokes the CanIDeploy service with the basic auth credentials" do
|
92
|
-
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {token: "some token", verbose: 'verbose'})
|
92
|
+
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {pact_broker_base_url: 'http://pact-broker', token: "some token", verbose: 'verbose'})
|
93
93
|
invoke_can_i_deploy
|
94
94
|
end
|
95
95
|
end
|
@@ -66,7 +66,7 @@ module PactBroker
|
|
66
66
|
it "calls PactBroker::Client::Webhooks::Create with pact broker details" do
|
67
67
|
expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, broker_base_url, pact_broker_client_options |
|
68
68
|
expect(broker_base_url).to eq "http://broker"
|
69
|
-
expect(pact_broker_client_options).to eq(basic_auth: { username: "username", password: "password"}, verbose: true)
|
69
|
+
expect(pact_broker_client_options).to eq(pact_broker_base_url: 'http://broker', basic_auth: { username: "username", password: "password"}, verbose: true)
|
70
70
|
command_result
|
71
71
|
end
|
72
72
|
subject
|
@@ -92,7 +92,7 @@ module PactBroker
|
|
92
92
|
|
93
93
|
it "calls Webhooks::Create without basic auth" do
|
94
94
|
expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, _, pact_broker_client_options |
|
95
|
-
expect(pact_broker_client_options).to eq(verbose: true)
|
95
|
+
expect(pact_broker_client_options).to eq(verbose: true, pact_broker_base_url: 'http://broker')
|
96
96
|
command_result
|
97
97
|
end
|
98
98
|
subject
|
@@ -110,7 +110,7 @@ module PactBroker
|
|
110
110
|
it "calls Webhooks::Create without basic auth" do
|
111
111
|
|
112
112
|
expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, _, pact_broker_client_options |
|
113
|
-
expect(pact_broker_client_options).to eq(verbose: true, token: "token")
|
113
|
+
expect(pact_broker_client_options).to eq(verbose: true, token: "token", pact_broker_base_url: 'http://broker')
|
114
114
|
command_result
|
115
115
|
end
|
116
116
|
subject
|
@@ -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
|