pact_broker-client 1.40.0 → 1.45.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +21 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +57 -0
- data/Gemfile +4 -0
- data/README.md +39 -22
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +79 -280
- data/lib/pact_broker/client/backports.rb +9 -0
- data/lib/pact_broker/client/base_command.rb +98 -0
- data/lib/pact_broker/client/can_i_deploy.rb +57 -5
- data/lib/pact_broker/client/cli/broker.rb +23 -76
- data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
- data/lib/pact_broker/client/cli/deployment_commands.rb +94 -0
- data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
- data/lib/pact_broker/client/cli/pacticipant_commands.rb +53 -0
- data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -55
- data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
- data/lib/pact_broker/client/colorize_notices.rb +31 -0
- data/lib/pact_broker/client/deployments.rb +4 -0
- data/lib/pact_broker/client/deployments/record_deployment.rb +38 -0
- data/lib/pact_broker/client/deployments/record_release.rb +99 -0
- data/lib/pact_broker/client/deployments/record_support_ended.rb +103 -0
- data/lib/pact_broker/client/deployments/record_undeployment.rb +127 -0
- data/lib/pact_broker/client/describe_text_formatter.rb +23 -0
- data/lib/pact_broker/client/environments.rb +6 -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 +26 -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 +31 -6
- data/lib/pact_broker/client/hal/http_client.rb +8 -2
- 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.rb +4 -0
- data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
- data/lib/pact_broker/client/matrix/resource.rb +26 -1
- data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
- 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/describe.rb +33 -0
- 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/publish_pacts.rb +6 -2
- data/lib/pact_broker/client/string_refinements.rb +56 -0
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions.rb +4 -1
- data/lib/pact_broker/client/versions/describe.rb +3 -1
- data/lib/pact_broker/client/versions/formatter.rb +3 -1
- data/lib/pact_broker/client/versions/json_formatter.rb +5 -3
- data/lib/pact_broker/client/versions/text_formatter.rb +3 -1
- data/pact-broker-client.gemspec +2 -0
- data/script/approve-all.sh +6 -0
- data/script/publish-pact.sh +12 -9
- data/script/record-deployments-and-releases.sh +18 -0
- data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +7 -0
- data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
- data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +7 -0
- data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
- data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
- data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
- data/spec/integration/describe_environment_spec.rb +31 -0
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +109 -7
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +19 -6
- 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/cli/version_selector_options_parser_spec.rb +21 -0
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -0
- data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +208 -0
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +219 -0
- 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/pacts/pact_broker_client-pact_broker.json +88 -287
- data/spec/service_providers/create_environment_spec.rb +78 -0
- data/spec/service_providers/list_environments_spec.rb +77 -0
- data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
- data/spec/service_providers/pact_broker_client_register_repository_spec.rb +2 -2
- data/spec/service_providers/pacticipants_create_spec.rb +5 -4
- data/spec/service_providers/publish_pacts_spec.rb +5 -2
- data/spec/service_providers/record_deployment_spec.rb +17 -36
- data/spec/service_providers/record_release_spec.rb +132 -0
- data/spec/service_providers/record_undeployment_spec.rb +166 -0
- data/spec/spec_helper.rb +15 -2
- data/spec/support/approvals.rb +26 -0
- data/spec/support/shared_context.rb +8 -3
- data/tasks/pact.rake +21 -1
- metadata +104 -7
- data/lib/pact_broker/client/versions/record_deployment.rb +0 -109
- data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -82
@@ -25,7 +25,8 @@ module PactBroker
|
|
25
25
|
verbose: 'verbose',
|
26
26
|
retry_while_unknown: 1,
|
27
27
|
retry_interval: 2,
|
28
|
-
limit: 1000
|
28
|
+
limit: 1000,
|
29
|
+
dry_run: false
|
29
30
|
}
|
30
31
|
end
|
31
32
|
|
@@ -37,7 +38,7 @@ module PactBroker
|
|
37
38
|
end
|
38
39
|
|
39
40
|
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}, {output: 'table', retry_while_unknown: 1, retry_interval: 2}, {verbose: 'verbose'})
|
41
|
+
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, dry_run: false}, { pact_broker_base_url: 'http://pact-broker', verbose: 'verbose' })
|
41
42
|
invoke_can_i_deploy
|
42
43
|
end
|
43
44
|
|
@@ -55,7 +56,7 @@ module PactBroker
|
|
55
56
|
end
|
56
57
|
|
57
58
|
it "passes the value as the matrix options" do
|
58
|
-
expect(CanIDeploy).to receive(:call).with(anything, anything, {to_tag: 'prod', to_environment: nil, limit: 1000}, anything, anything)
|
59
|
+
expect(CanIDeploy).to receive(:call).with(anything, anything, {to_tag: 'prod', to_environment: nil, limit: 1000, ignore_selectors: []}, anything, anything)
|
59
60
|
invoke_can_i_deploy
|
60
61
|
end
|
61
62
|
end
|
@@ -66,7 +67,7 @@ module PactBroker
|
|
66
67
|
end
|
67
68
|
|
68
69
|
it "passes the value as the matrix options" do
|
69
|
-
expect(CanIDeploy).to receive(:call).with(anything, anything, {to_tag: nil, to_environment: 'prod', limit: 1000}, anything, anything)
|
70
|
+
expect(CanIDeploy).to receive(:call).with(anything, anything, {to_tag: nil, to_environment: 'prod', limit: 1000, ignore_selectors: []}, anything, anything)
|
70
71
|
invoke_can_i_deploy
|
71
72
|
end
|
72
73
|
end
|
@@ -78,7 +79,7 @@ module PactBroker
|
|
78
79
|
end
|
79
80
|
|
80
81
|
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'})
|
82
|
+
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
83
|
invoke_can_i_deploy
|
83
84
|
end
|
84
85
|
end
|
@@ -89,7 +90,19 @@ module PactBroker
|
|
89
90
|
end
|
90
91
|
|
91
92
|
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'})
|
93
|
+
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {pact_broker_base_url: 'http://pact-broker', token: "some token", verbose: 'verbose'})
|
94
|
+
invoke_can_i_deploy
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when PACT_BROKER_CAN_I_DEPLOY_DRY_RUN=true" do
|
99
|
+
before do
|
100
|
+
allow(ENV).to receive(:[]).and_call_original
|
101
|
+
allow(ENV).to receive(:[]).with("PACT_BROKER_CAN_I_DEPLOY_DRY_RUN").and_return("true")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "invokes the CanIDeploy service with dry_run set to true" do
|
105
|
+
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, hash_including(dry_run: true), anything)
|
93
106
|
invoke_can_i_deploy
|
94
107
|
end
|
95
108
|
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
|
@@ -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,204 @@
|
|
1
|
+
require 'pact_broker/client/deployments/record_deployment'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module Deployments
|
6
|
+
describe RecordDeployment do
|
7
|
+
describe ".call" do
|
8
|
+
let(:broker_base_url) { "http://broker" }
|
9
|
+
let(:index_body_hash) do
|
10
|
+
{
|
11
|
+
_links: {
|
12
|
+
"pb:environments" => { href: "#{broker_base_url}/environments" },
|
13
|
+
"pb:pacticipant-version" => {
|
14
|
+
href: "#{broker_base_url}/pacticipants/{pacticipant}/versions/{version}"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
let(:version_body_hash) do
|
20
|
+
{
|
21
|
+
"_links" => {
|
22
|
+
"pb:record-deployment" => [
|
23
|
+
{
|
24
|
+
name: "test",
|
25
|
+
href: "#{broker_base_url}/record-deployment"
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
let(:environments_body_hash) do
|
32
|
+
{
|
33
|
+
"_links" => {
|
34
|
+
"pb:environments" => [
|
35
|
+
{
|
36
|
+
"name" => "test",
|
37
|
+
"href" => ""
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
43
|
+
end
|
44
|
+
let(:record_deployment_body_hash) do
|
45
|
+
{ "some" => "response" }
|
46
|
+
end
|
47
|
+
let!(:index_request) do
|
48
|
+
stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
49
|
+
end
|
50
|
+
let!(:version_request) do
|
51
|
+
stub_request(:get, broker_base_url + "/pacticipants/Foo/versions/1").to_return(status: 200, body: version_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
52
|
+
end
|
53
|
+
|
54
|
+
let!(:environments_request) do
|
55
|
+
stub_request(:get, "http://broker/environments").
|
56
|
+
with(headers: { 'Accept'=>'application/hal+json' }).
|
57
|
+
to_return(status: 200, body: environments_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
|
58
|
+
end
|
59
|
+
let!(:record_deployment_request) do
|
60
|
+
stub_request(:post, "http://broker/record-deployment").
|
61
|
+
to_return(status: 200, body: record_deployment_body_hash.to_json , headers: {})
|
62
|
+
end
|
63
|
+
|
64
|
+
let(:target) { "blue" }
|
65
|
+
|
66
|
+
let(:params) do
|
67
|
+
{
|
68
|
+
pacticipant_name: "Foo",
|
69
|
+
version_number: "1",
|
70
|
+
environment_name: "test",
|
71
|
+
target: target
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:options) do
|
76
|
+
{
|
77
|
+
output: output,
|
78
|
+
verbose: true
|
79
|
+
}
|
80
|
+
end
|
81
|
+
let(:output) { "text" }
|
82
|
+
let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url} }
|
83
|
+
|
84
|
+
subject { RecordDeployment.call(params, options, pact_broker_client_options) }
|
85
|
+
|
86
|
+
context "when the pb:environments relation does not exist" do
|
87
|
+
let(:index_body_hash) do
|
88
|
+
{
|
89
|
+
"_links" => {}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
it "returns an error response" do
|
93
|
+
expect(subject.success).to be false
|
94
|
+
expect(subject.message).to include "does not support"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when the specified version does not exist" do
|
99
|
+
let!(:version_request) do
|
100
|
+
stub_request(:get, broker_base_url + "/pacticipants/Foo/versions/1").to_return(status: 404)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "returns an error response" do
|
104
|
+
expect(subject.success).to be false
|
105
|
+
expect(subject.message).to include "Foo version 1 not found"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when the pacticipant version does not support recording deployments" do
|
110
|
+
let(:version_body_hash) do
|
111
|
+
{
|
112
|
+
"_links" => {}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
it "returns an error response" do
|
116
|
+
expect(subject.success).to be false
|
117
|
+
expect(subject.message).to include "does not support"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when the specified environment is not available for recording a deployment" do
|
122
|
+
let(:version_body_hash) do
|
123
|
+
{
|
124
|
+
"_links" => {
|
125
|
+
"pb:record-deployment" => [
|
126
|
+
{
|
127
|
+
"name" => "prod",
|
128
|
+
"href" => ""
|
129
|
+
}
|
130
|
+
]
|
131
|
+
}
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when the environment does not exist" do
|
136
|
+
let(:environments_body_hash) do
|
137
|
+
{
|
138
|
+
"_links" => {
|
139
|
+
"pb:environments" => [
|
140
|
+
{
|
141
|
+
"name" => "prod",
|
142
|
+
"href" => ""
|
143
|
+
},{
|
144
|
+
"name" => "uat",
|
145
|
+
"href" => ""
|
146
|
+
}
|
147
|
+
]
|
148
|
+
}
|
149
|
+
}
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns an error response" do
|
153
|
+
expect(subject.success).to be false
|
154
|
+
expect(subject.message).to include "No environment found with name 'test'. Available options: prod"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "when the environment does exist" do
|
159
|
+
it "returns an error response" do
|
160
|
+
expect(subject.success).to be false
|
161
|
+
expect(subject.message).to include "Environment 'test' is not an available option for recording a deployment of Foo. Available options: prod"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when the output is json" do
|
167
|
+
let(:output) { "json" }
|
168
|
+
|
169
|
+
it "returns the JSON payload" do
|
170
|
+
expect(JSON.parse(subject.message)).to eq record_deployment_body_hash
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "when the response headers contain Pactflow" do
|
175
|
+
before do
|
176
|
+
allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
|
177
|
+
allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
|
178
|
+
allow_any_instance_of(RecordDeployment).to receive(:record_action)
|
179
|
+
allow_any_instance_of(RecordDeployment).to receive(:index_resource).and_return(index_resource)
|
180
|
+
end
|
181
|
+
|
182
|
+
let(:response_headers) { { "X-Pactflow-Sha" => "abc" } }
|
183
|
+
|
184
|
+
let(:index_resource) do
|
185
|
+
double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
|
186
|
+
end
|
187
|
+
|
188
|
+
it "indicates the API was Pactflow" do
|
189
|
+
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment (target blue) in Pactflow"
|
190
|
+
end
|
191
|
+
|
192
|
+
context "when target is nil" do
|
193
|
+
let(:target) { nil }
|
194
|
+
|
195
|
+
it "does not include the target in the result message" do
|
196
|
+
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment in"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'pact_broker/client/deployments/record_support_ended'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module Deployments
|
6
|
+
describe RecordSupportEnded do
|
7
|
+
let(:params) do
|
8
|
+
{
|
9
|
+
pacticipant_name: "Foo",
|
10
|
+
version_number: version_number,
|
11
|
+
environment_name: "test"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
let(:version_number) { "2" }
|
15
|
+
let(:output) { "text" }
|
16
|
+
let(:options) { { output: output, verbose: true } }
|
17
|
+
let(:pact_broker_base_url) { "http://broker" }
|
18
|
+
let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
|
19
|
+
|
20
|
+
let(:index_body_hash) do
|
21
|
+
{
|
22
|
+
_links: {
|
23
|
+
:'pb:environments' => {
|
24
|
+
href: environments_url
|
25
|
+
},
|
26
|
+
:'pb:pacticipant' => {
|
27
|
+
href: pacticipant_url
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:environments_hash) do
|
34
|
+
{
|
35
|
+
_links: {
|
36
|
+
:'pb:environments' => [
|
37
|
+
{
|
38
|
+
name: "test",
|
39
|
+
href: test_environment_url
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:environment_hash) do
|
47
|
+
{
|
48
|
+
_links: {
|
49
|
+
:'pb:currently-supported-versions' => {
|
50
|
+
href: currently_supported_versions_url
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:supported_versions_hash) do
|
57
|
+
{
|
58
|
+
_embedded: {
|
59
|
+
releasedVersions: [
|
60
|
+
{
|
61
|
+
number: "customer-1",
|
62
|
+
_links: {
|
63
|
+
self: {
|
64
|
+
href: supported_version_url_1
|
65
|
+
}
|
66
|
+
}
|
67
|
+
},
|
68
|
+
{
|
69
|
+
number: returned_target_2,
|
70
|
+
_links: {
|
71
|
+
self: {
|
72
|
+
href: supported_version_url_2
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:returned_target_2) { nil }
|
82
|
+
let(:supported_version_hash) do
|
83
|
+
{
|
84
|
+
_embedded: {
|
85
|
+
version: {
|
86
|
+
number: "2"
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:environments_url) { "#{webmock_base_url}/environments" }
|
93
|
+
let(:test_environment_url) { "#{webmock_base_url}/environments/1234" }
|
94
|
+
let(:currently_supported_versions_url) { "#{webmock_base_url}/currently-deployed-versions" }
|
95
|
+
let(:supported_version_url_1) { "#{webmock_base_url}/deployed-version-1" }
|
96
|
+
let(:supported_version_url_2) { "#{webmock_base_url}/deployed-version-2" }
|
97
|
+
let(:pacticipant_url) { "#{webmock_base_url}/pacticipant" }
|
98
|
+
|
99
|
+
let(:webmock_base_url) { "http://broker" }
|
100
|
+
|
101
|
+
let!(:index_request) do
|
102
|
+
stub_request(:get, "http://broker").to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
103
|
+
end
|
104
|
+
|
105
|
+
let!(:environments_request) do
|
106
|
+
stub_request(:get, "http://broker/environments").to_return(status: 200, body: environments_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
107
|
+
end
|
108
|
+
|
109
|
+
let!(:environment_request) do
|
110
|
+
stub_request(:get, test_environment_url).to_return(status: 200, body: environment_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
111
|
+
end
|
112
|
+
|
113
|
+
let!(:supported_versions_request) do
|
114
|
+
stub_request(:get, currently_supported_versions_url + "?pacticipant=Foo&version=2").to_return(status: 200, body: supported_versions_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
115
|
+
end
|
116
|
+
|
117
|
+
let!(:supported_version_patch_request_1) do
|
118
|
+
stub_request(:patch, supported_version_url_1).with(body: { currentlySupported: false}.to_json).to_return(status: 200, body: supported_version_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
|
119
|
+
end
|
120
|
+
|
121
|
+
let!(:supported_version_patch_request_2) do
|
122
|
+
stub_request(:patch, supported_version_url_2).with(body: { currentlySupported: false}.to_json).to_return(status: 200, body: supported_version_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
|
123
|
+
end
|
124
|
+
|
125
|
+
let!(:pacticipant_request) do
|
126
|
+
stub_request(:get, pacticipant_url).to_return(status: pacticipant_request_status, body: {}.to_json, headers: { "Content-Type" => "application/hal+json" })
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:pacticipant_request_status) { 200 }
|
130
|
+
|
131
|
+
subject { RecordSupportEnded.call(params, options, pact_broker_client_options) }
|
132
|
+
|
133
|
+
its(:success) { is_expected.to eq true }
|
134
|
+
its(:message) { is_expected.to include "Recorded support ended for Foo version 2 in test environment in the Pact Broker" }
|
135
|
+
|
136
|
+
context "when there is no pb:environments relation in the index" do
|
137
|
+
let(:index_body_hash) do
|
138
|
+
{
|
139
|
+
_links: {}
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
its(:success) { is_expected.to be false }
|
144
|
+
its(:message) { is_expected.to include "support" }
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when output is json" do
|
148
|
+
let(:output) { "json" }
|
149
|
+
its(:message) { is_expected.to eq [supported_version_hash, supported_version_hash].to_json }
|
150
|
+
end
|
151
|
+
|
152
|
+
context "when there is an error returned from one of the supported version updates (there should only ever be one supported version, but testing just for the sake of it)" do
|
153
|
+
let!(:supported_version_patch_request_2) do
|
154
|
+
stub_request(:patch, supported_version_url_2).to_return(status: 400, body: { errors: { foo: ["some error"]}}.to_json, headers: { "Content-Type" => "application/hal+json" })
|
155
|
+
end
|
156
|
+
|
157
|
+
let(:returned_target_2) { "customer-1" }
|
158
|
+
|
159
|
+
its(:success) { is_expected.to be false }
|
160
|
+
its(:message) { is_expected.to include "Recorded" }
|
161
|
+
its(:message) { is_expected.to include "some error" }
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when there is no currently-deployed-versions relation in the environment resource" do
|
165
|
+
let(:environment_hash) do
|
166
|
+
{
|
167
|
+
_links: {}
|
168
|
+
}
|
169
|
+
end
|
170
|
+
|
171
|
+
its(:success) { is_expected.to be false }
|
172
|
+
its(:message) { is_expected.to include "support" }
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when there is no matching supported versions" do
|
176
|
+
let(:supported_versions_hash) do
|
177
|
+
{
|
178
|
+
_embedded: {
|
179
|
+
releasedVersions: []
|
180
|
+
}
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
184
|
+
let(:expected_message) { "Foo version 2 is not currently released in test environment. Cannot record support ended." }
|
185
|
+
|
186
|
+
its(:success) { is_expected.to be false }
|
187
|
+
its(:message) { is_expected.to include expected_message }
|
188
|
+
|
189
|
+
context "when there are no supported versions for the pacticipant" do
|
190
|
+
context "when the pacticipant does not exist" do
|
191
|
+
let(:pacticipant_request_status) { 404 }
|
192
|
+
|
193
|
+
its(:success) { is_expected.to be false }
|
194
|
+
its(:message) { is_expected.to include "No pacticipant with name 'Foo' found" }
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when output is json" do
|
199
|
+
let(:output) { "json" }
|
200
|
+
|
201
|
+
its(:message) { is_expected.to eq({ error: { message: expected_message } }.to_json) }
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|