pact_broker-client 1.60.0 → 1.62.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +44 -11
- data/bin/pactflow +4 -0
- data/doc/pacts/markdown/Pact Broker Client - Pactflow.md +36 -0
- data/lib/pact_broker/client/cli/broker.rb +15 -199
- data/lib/pact_broker/client/cli/custom_thor.rb +23 -0
- data/lib/pact_broker/client/cli/pact_commands.rb +128 -0
- data/lib/pact_broker/client/cli/version_commands.rb +102 -0
- data/lib/pact_broker/client/deployments/record_deployment.rb +3 -0
- data/lib/pact_broker/client/deployments/record_undeployment.rb +3 -0
- data/lib/pact_broker/client/environments/environment_command.rb +3 -0
- data/lib/pact_broker/client/hal/links.rb +3 -0
- data/lib/pact_broker/client/hal_client_methods.rb +4 -0
- data/lib/pact_broker/client/hash_refinements.rb +9 -0
- data/lib/pact_broker/client/pacticipants/create.rb +1 -1
- data/lib/pact_broker/client/publish_pacts.rb +1 -0
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions/create.rb +111 -0
- data/lib/pact_broker/client/versions.rb +1 -0
- data/lib/pact_broker/client/webhooks/create.rb +3 -0
- data/lib/pactflow/client/cli/pactflow.rb +12 -0
- data/lib/pactflow/client/cli/provider_contract_commands.rb +68 -0
- data/lib/pactflow/client/provider_contracts/publish.rb +79 -0
- data/pact-broker-client.gemspec +1 -1
- data/script/oas.yml +49 -0
- data/script/publish-provider-contract.sh +27 -0
- data/script/record-undeployment.sh +1 -1
- data/script/update-cli-usage-in-readme.rb +1 -1
- data/script/verification-results.txt +1 -0
- data/spec/lib/pact_broker/client/versions/create_spec.rb +174 -0
- data/spec/pacts/pact_broker_client-pactflow.json +30 -0
- data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +92 -0
- metadata +20 -5
@@ -0,0 +1,174 @@
|
|
1
|
+
require "pact_broker/client/versions/create"
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
describe Versions::Create do
|
6
|
+
describe "#call" do
|
7
|
+
let(:index_body) do
|
8
|
+
{
|
9
|
+
"_links" => {
|
10
|
+
"pb:pacticipant-branch-version" => {
|
11
|
+
"href" => "http://broker/pacticipants/{pacticipant}/branches/{branch}/versions/{version}"
|
12
|
+
},
|
13
|
+
"pb:pacticipant-version-tag" => {
|
14
|
+
"href" => "http://broker/pacticipants/{pacticipant}/versions/{version}/tags/{tag}"
|
15
|
+
},
|
16
|
+
"pb:pacticipant-version" => {
|
17
|
+
"href" => "http://broker/pacticipants/{pacticipant}/versions/{version}"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
let!(:index_request) do
|
24
|
+
stub_request(:get, "http://broker").to_return(status: 200, body: index_body.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
25
|
+
end
|
26
|
+
|
27
|
+
let!(:branch_request) do
|
28
|
+
stub_request(:put, "http://broker/pacticipants/Foo/branches/main/versions/1").to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/hal+json" } )
|
29
|
+
end
|
30
|
+
|
31
|
+
let!(:tag_request) do
|
32
|
+
stub_request(:put, "http://broker/pacticipants/Foo/versions/1/tags/dev").to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/hal+json" } )
|
33
|
+
end
|
34
|
+
|
35
|
+
let!(:create_version_request) do
|
36
|
+
stub_request(:put, "http://broker/pacticipants/Foo/versions/1").to_return(status: 200, body: { version: "created" }.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
37
|
+
end
|
38
|
+
|
39
|
+
let!(:get_version_request) do
|
40
|
+
stub_request(:get, "http://broker/pacticipants/Foo/versions/1").to_return(status: 200, body: { version: "got" }.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:params) do
|
44
|
+
{
|
45
|
+
pacticipant_name: "Foo",
|
46
|
+
version_number: "1",
|
47
|
+
branch_name: branch_name,
|
48
|
+
tags: tags
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:branch_name) { "main" }
|
53
|
+
let(:tags) { ["dev"] }
|
54
|
+
|
55
|
+
let(:options) do
|
56
|
+
{
|
57
|
+
verbose: "verbose",
|
58
|
+
output: output
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:output) { "text" }
|
63
|
+
|
64
|
+
let(:pact_broker_client_options) do
|
65
|
+
{
|
66
|
+
token: "token",
|
67
|
+
pact_broker_base_url: "http://broker"
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
subject { PactBroker::Client::Versions::Create.call(params, options, pact_broker_client_options)}
|
72
|
+
|
73
|
+
context "with a branch and tags" do
|
74
|
+
it "creates a branch version" do
|
75
|
+
subject
|
76
|
+
expect(branch_request).to have_been_made
|
77
|
+
end
|
78
|
+
|
79
|
+
it "creates the tag" do
|
80
|
+
subject
|
81
|
+
expect(tag_request).to have_been_made
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns a message" do
|
85
|
+
expect(subject.message).to include "Created/updated pacticipant version 1 with branch main and tag(s) dev in the Pact Broker"
|
86
|
+
expect(subject.success).to be true
|
87
|
+
end
|
88
|
+
|
89
|
+
context "without output json" do
|
90
|
+
let(:output) { "json" }
|
91
|
+
|
92
|
+
it "returns a json message" do
|
93
|
+
expect(subject.message).to eq({ version: "got" }.to_json)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with only tags" do
|
99
|
+
let(:branch_name) { nil }
|
100
|
+
|
101
|
+
it "returns a message" do
|
102
|
+
expect(subject.message).to include "Created/updated pacticipant version 1 with tag(s) dev in the Pact Broker"
|
103
|
+
expect(subject.success).to be true
|
104
|
+
end
|
105
|
+
|
106
|
+
context "without output json" do
|
107
|
+
let(:output) { "json" }
|
108
|
+
|
109
|
+
it "returns a json message" do
|
110
|
+
expect(subject.message).to eq({ version: "got" }.to_json)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with only a branch" do
|
116
|
+
let(:tags) { nil }
|
117
|
+
|
118
|
+
it "returns a message" do
|
119
|
+
expect(subject.message).to include "Created/updated pacticipant version 1 with branch main in the Pact Broker"
|
120
|
+
expect(subject.success).to be true
|
121
|
+
end
|
122
|
+
|
123
|
+
context "without output json" do
|
124
|
+
let(:output) { "json" }
|
125
|
+
|
126
|
+
it "returns a json message" do
|
127
|
+
expect(subject.message).to eq({ version: "got" }.to_json)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "with no branch or tags" do
|
133
|
+
let(:tags) { nil }
|
134
|
+
let(:branch_name) { nil }
|
135
|
+
|
136
|
+
it "creates a version" do
|
137
|
+
subject
|
138
|
+
expect(create_version_request).to have_been_made
|
139
|
+
end
|
140
|
+
|
141
|
+
it "returns a message" do
|
142
|
+
expect(subject.message).to include "Created/updated pacticipant version 1 in the Pact Broker"
|
143
|
+
expect(subject.success).to be true
|
144
|
+
end
|
145
|
+
|
146
|
+
context "without output json" do
|
147
|
+
let(:output) { "json" }
|
148
|
+
|
149
|
+
it "returns a json message" do
|
150
|
+
expect(subject.message).to eq({ version: "created" }.to_json)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "when the Pact Broker does not support branch versions" do
|
156
|
+
before do
|
157
|
+
index_body["_links"].delete("pb:pacticipant-branch-version")
|
158
|
+
end
|
159
|
+
|
160
|
+
let(:index_body) do
|
161
|
+
{
|
162
|
+
"_links" => {}
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
it "returns an error" do
|
167
|
+
expect(subject.message).to include "does not support branch versions"
|
168
|
+
expect(subject.success).to be false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -6,6 +6,36 @@
|
|
6
6
|
"name": "Pactflow"
|
7
7
|
},
|
8
8
|
"interactions": [
|
9
|
+
{
|
10
|
+
"description": "a request to create a provider contract",
|
11
|
+
"request": {
|
12
|
+
"method": "put",
|
13
|
+
"path": "/contracts/provider/Bar/version/1",
|
14
|
+
"headers": {
|
15
|
+
"Content-Type": "application/json",
|
16
|
+
"Accept": "application/hal+json"
|
17
|
+
},
|
18
|
+
"body": {
|
19
|
+
"content": "LS0tCjpzb21lOiBjb250cmFjdAo=",
|
20
|
+
"contractType": "oas",
|
21
|
+
"contentType": "application/yaml",
|
22
|
+
"verificationResults": {
|
23
|
+
"success": true,
|
24
|
+
"content": "c29tZSByZXN1bHRz",
|
25
|
+
"contentType": "text/plain",
|
26
|
+
"format": "text",
|
27
|
+
"verifier": "my custom tool",
|
28
|
+
"verifierVersion": "1.0"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
},
|
32
|
+
"response": {
|
33
|
+
"status": 201,
|
34
|
+
"headers": {
|
35
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
9
39
|
{
|
10
40
|
"description": "a request for the index resource",
|
11
41
|
"request": {
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative "pact_helper"
|
2
|
+
require "pactflow/client/provider_contracts/publish"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
RSpec.describe "publishing a provider contract to Pactflow", pact: true do
|
6
|
+
before do
|
7
|
+
# no point re-testing this
|
8
|
+
allow(PactBroker::Client::Versions::Create).to receive(:call).and_return(double("result", success: true))
|
9
|
+
end
|
10
|
+
|
11
|
+
include_context "pact broker"
|
12
|
+
include PactBrokerPactHelperMethods
|
13
|
+
|
14
|
+
let(:command_params) do
|
15
|
+
{
|
16
|
+
provider_name: "Bar",
|
17
|
+
provider_version_number: "1",
|
18
|
+
branch_name: "main",
|
19
|
+
tags: ["dev"],
|
20
|
+
contract: {
|
21
|
+
content: { some: "contract" }.to_yaml,
|
22
|
+
content_type: "application/yaml",
|
23
|
+
specification: "oas"
|
24
|
+
},
|
25
|
+
verification_results: {
|
26
|
+
success: true,
|
27
|
+
content: "some results",
|
28
|
+
content_type: "text/plain",
|
29
|
+
format: "text",
|
30
|
+
verifier: "my custom tool",
|
31
|
+
verifier_version: "1.0"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:body) { { some: "body" }.to_json }
|
37
|
+
|
38
|
+
let(:request_body) do
|
39
|
+
{
|
40
|
+
"content" => "LS0tCjpzb21lOiBjb250cmFjdAo=",
|
41
|
+
"contractType" => "oas",
|
42
|
+
"contentType" => "application/yaml",
|
43
|
+
"verificationResults" => {
|
44
|
+
"success" => true,
|
45
|
+
"content" => "c29tZSByZXN1bHRz",
|
46
|
+
"contentType" => "text/plain",
|
47
|
+
"format" => "text",
|
48
|
+
"verifier" => "my custom tool",
|
49
|
+
"verifierVersion" => "1.0"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:response_status) { 201 }
|
55
|
+
let(:success_response) do
|
56
|
+
{
|
57
|
+
status: response_status,
|
58
|
+
headers: pact_broker_response_headers
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:options) do
|
63
|
+
{
|
64
|
+
verbose: false
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:pact_broker_client_options) do
|
69
|
+
{ pact_broker_base_url: pactflow.mock_service_base_url }
|
70
|
+
end
|
71
|
+
|
72
|
+
subject { Pactflow::Client::ProviderContracts::Publish.call(command_params, options, pact_broker_client_options) }
|
73
|
+
|
74
|
+
context "creating a provider contract with valid parameters" do
|
75
|
+
before do
|
76
|
+
pactflow
|
77
|
+
.upon_receiving("a request to create a provider contract")
|
78
|
+
.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
|
+
end
|
91
|
+
end
|
92
|
+
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.
|
4
|
+
version: 1.62.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: 2022-05-
|
11
|
+
date: 2022-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -176,14 +176,14 @@ dependencies:
|
|
176
176
|
requirements:
|
177
177
|
- - '='
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: 0.0.
|
179
|
+
version: 0.0.18
|
180
180
|
type: :development
|
181
181
|
prerelease: false
|
182
182
|
version_requirements: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
184
|
- - '='
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version: 0.0.
|
186
|
+
version: 0.0.18
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: rspec-its
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,6 +204,7 @@ email:
|
|
204
204
|
- beth@bethesque.com
|
205
205
|
executables:
|
206
206
|
- pact-broker
|
207
|
+
- pactflow
|
207
208
|
extensions: []
|
208
209
|
extra_rdoc_files: []
|
209
210
|
files:
|
@@ -220,6 +221,7 @@ files:
|
|
220
221
|
- Rakefile
|
221
222
|
- appveyor.yml
|
222
223
|
- bin/pact-broker
|
224
|
+
- bin/pactflow
|
223
225
|
- ci.sh
|
224
226
|
- doc/CAN_I_DEPLOY_USAGE_WITH_TAGS.md
|
225
227
|
- doc/pacts/markdown/Pact Broker Client - Pact Broker.md
|
@@ -245,8 +247,10 @@ files:
|
|
245
247
|
- lib/pact_broker/client/cli/deployment_commands.rb
|
246
248
|
- lib/pact_broker/client/cli/environment_commands.rb
|
247
249
|
- lib/pact_broker/client/cli/matrix_commands.rb
|
250
|
+
- lib/pact_broker/client/cli/pact_commands.rb
|
248
251
|
- lib/pact_broker/client/cli/pacticipant_commands.rb
|
249
252
|
- lib/pact_broker/client/cli/record_deployment_long_desc.txt
|
253
|
+
- lib/pact_broker/client/cli/version_commands.rb
|
250
254
|
- lib/pact_broker/client/cli/version_selector_options_parser.rb
|
251
255
|
- lib/pact_broker/client/cli/webhook_commands.rb
|
252
256
|
- lib/pact_broker/client/colorize_notices.rb
|
@@ -304,6 +308,7 @@ files:
|
|
304
308
|
- lib/pact_broker/client/verification_required.rb
|
305
309
|
- lib/pact_broker/client/version.rb
|
306
310
|
- lib/pact_broker/client/versions.rb
|
311
|
+
- lib/pact_broker/client/versions/create.rb
|
307
312
|
- lib/pact_broker/client/versions/describe.rb
|
308
313
|
- lib/pact_broker/client/versions/formatter.rb
|
309
314
|
- lib/pact_broker/client/versions/json_formatter.rb
|
@@ -311,17 +316,23 @@ files:
|
|
311
316
|
- lib/pact_broker/client/webhooks/create.rb
|
312
317
|
- lib/pact_broker/client/webhooks/test.rb
|
313
318
|
- lib/pact_broker_client.rb
|
319
|
+
- lib/pactflow/client/cli/pactflow.rb
|
320
|
+
- lib/pactflow/client/cli/provider_contract_commands.rb
|
321
|
+
- lib/pactflow/client/provider_contracts/publish.rb
|
314
322
|
- pact-broker-client.gemspec
|
315
323
|
- script/approve-all.sh
|
316
324
|
- script/can-i-deploy.sh
|
317
325
|
- script/create-pacticipant.sh
|
326
|
+
- script/oas.yml
|
318
327
|
- script/publish-pact.sh
|
328
|
+
- script/publish-provider-contract.sh
|
319
329
|
- script/record-deployment.sh
|
320
330
|
- script/record-deployments-and-releases.sh
|
321
331
|
- script/record-undeployment.sh
|
322
332
|
- script/release.sh
|
323
333
|
- script/trigger-release.sh
|
324
334
|
- script/update-cli-usage-in-readme.rb
|
335
|
+
- script/verification-results.txt
|
325
336
|
- script/webhook-commands.sh
|
326
337
|
- spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt
|
327
338
|
- spec/fixtures/approvals/can_i_deploy_ignore.approved.txt
|
@@ -365,6 +376,7 @@ files:
|
|
365
376
|
- spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb
|
366
377
|
- spec/lib/pact_broker/client/retry_spec.rb
|
367
378
|
- spec/lib/pact_broker/client/tasks/publication_task_spec.rb
|
379
|
+
- spec/lib/pact_broker/client/versions/create_spec.rb
|
368
380
|
- spec/lib/pact_broker/client/versions/describe_spec.rb
|
369
381
|
- spec/lib/pact_broker/client/versions_spec.rb
|
370
382
|
- spec/lib/pact_broker/client/webhooks/create_spec.rb
|
@@ -385,6 +397,7 @@ files:
|
|
385
397
|
- spec/service_providers/pact_broker_client_tags_spec.rb
|
386
398
|
- spec/service_providers/pact_broker_client_versions_spec.rb
|
387
399
|
- spec/service_providers/pact_helper.rb
|
400
|
+
- spec/service_providers/pactflow_publish_provider_contract_spec.rb
|
388
401
|
- spec/service_providers/pactflow_webhooks_create_spec.rb
|
389
402
|
- spec/service_providers/pacticipants_create_spec.rb
|
390
403
|
- spec/service_providers/publish_pacts_spec.rb
|
@@ -425,7 +438,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
425
438
|
- !ruby/object:Gem::Version
|
426
439
|
version: '0'
|
427
440
|
requirements: []
|
428
|
-
rubygems_version: 3.3.
|
441
|
+
rubygems_version: 3.3.13
|
429
442
|
signing_key:
|
430
443
|
specification_version: 4
|
431
444
|
summary: See description
|
@@ -472,6 +485,7 @@ test_files:
|
|
472
485
|
- spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb
|
473
486
|
- spec/lib/pact_broker/client/retry_spec.rb
|
474
487
|
- spec/lib/pact_broker/client/tasks/publication_task_spec.rb
|
488
|
+
- spec/lib/pact_broker/client/versions/create_spec.rb
|
475
489
|
- spec/lib/pact_broker/client/versions/describe_spec.rb
|
476
490
|
- spec/lib/pact_broker/client/versions_spec.rb
|
477
491
|
- spec/lib/pact_broker/client/webhooks/create_spec.rb
|
@@ -492,6 +506,7 @@ test_files:
|
|
492
506
|
- spec/service_providers/pact_broker_client_tags_spec.rb
|
493
507
|
- spec/service_providers/pact_broker_client_versions_spec.rb
|
494
508
|
- spec/service_providers/pact_helper.rb
|
509
|
+
- spec/service_providers/pactflow_publish_provider_contract_spec.rb
|
495
510
|
- spec/service_providers/pactflow_webhooks_create_spec.rb
|
496
511
|
- spec/service_providers/pacticipants_create_spec.rb
|
497
512
|
- spec/service_providers/publish_pacts_spec.rb
|