pact_broker-client 1.75.2 → 1.75.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/pact_broker/client/version.rb +1 -1
- metadata +19 -216
- data/.github/workflows/test.yml +0 -59
- data/.rspec +0 -3
- data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
- data/lib/pact_broker/client/webhooks/test.rb +0 -16
- data/pact-broker-client.gemspec +0 -30
- data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
- data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
- data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
- data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
- data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
- data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
- data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
- data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
- data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
- data/spec/fixtures/certificates/ca_cert.pem +0 -19
- data/spec/fixtures/certificates/ca_cert.srl +0 -1
- data/spec/fixtures/certificates/ca_key.pem +0 -28
- data/spec/fixtures/certificates/client_cert.pem +0 -17
- data/spec/fixtures/certificates/key.pem +0 -28
- data/spec/fixtures/certificates/server.csr +0 -15
- data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
- data/spec/fixtures/certificates/unsigned_key.pem +0 -28
- data/spec/fixtures/foo-bar.json +0 -31
- data/spec/integration/can_i_deploy_spec.rb +0 -24
- data/spec/integration/can_i_merge_spec.rb +0 -44
- data/spec/integration/create_version_tag_spec.rb +0 -20
- data/spec/integration/describe_environment_spec.rb +0 -31
- data/spec/integration/publish_provider_contract_spec.rb +0 -53
- data/spec/integration/unknown_options_spec.rb +0 -39
- data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
- data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
- data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
- data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
- data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
- data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
- data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
- data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
- data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
- data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
- data/spec/lib/pact_broker/client/git_spec.rb +0 -159
- data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
- data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
- data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
- data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
- data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
- data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
- data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
- data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
- data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
- data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
- data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
- data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
- data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
- data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
- data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
- data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
- data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
- data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
- data/spec/pacts/pact_broker_client-pactflow.json +0 -288
- data/spec/readme_spec.rb +0 -16
- data/spec/service_providers/create_environment_spec.rb +0 -78
- data/spec/service_providers/delete_branch_spec.rb +0 -68
- data/spec/service_providers/extra_goodies_spec.rb +0 -108
- data/spec/service_providers/list_environments_spec.rb +0 -77
- data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
- data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
- data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
- data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
- data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
- data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
- data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
- data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
- data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
- data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
- data/spec/service_providers/pact_helper.rb +0 -136
- data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
- data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
- data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
- data/spec/service_providers/pacticipants_create_spec.rb +0 -119
- data/spec/service_providers/publish_pacts_spec.rb +0 -114
- data/spec/service_providers/record_deployment_spec.rb +0 -199
- data/spec/service_providers/record_release_spec.rb +0 -130
- data/spec/service_providers/record_undeployment_spec.rb +0 -164
- data/spec/service_providers/webhooks_create_spec.rb +0 -391
- data/spec/spec_helper.rb +0 -68
- data/spec/support/approvals.rb +0 -26
- data/spec/support/cli_test_pacts/bar.json +0 -0
- data/spec/support/cli_test_pacts/foo.json +0 -0
- data/spec/support/latest_pacts_for_provider.json +0 -15
- data/spec/support/matrix.json +0 -35
- data/spec/support/matrix.txt +0 -3
- data/spec/support/matrix_error.txt +0 -3
- data/spec/support/matrix_with_results.txt +0 -10
- data/spec/support/pacticipant_get.json +0 -18
- data/spec/support/pacticipants_list.json +0 -26
- data/spec/support/pacts_latest_list.json +0 -41
- data/spec/support/shared_context.rb +0 -25
- data/spec/support/ssl_server.rb +0 -42
@@ -1,109 +0,0 @@
|
|
1
|
-
require_relative 'pact_helper'
|
2
|
-
require 'pact_broker/client'
|
3
|
-
|
4
|
-
module PactBroker::Client
|
5
|
-
describe Pacts, :pact => true do
|
6
|
-
|
7
|
-
include_context "pact broker"
|
8
|
-
|
9
|
-
describe "retrieving a pact" do
|
10
|
-
describe "retriving a specific version" do
|
11
|
-
before do
|
12
|
-
pact_broker.
|
13
|
-
given("the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0").
|
14
|
-
upon_receiving("a request retrieve a pact for a specific version").
|
15
|
-
with(
|
16
|
-
method: :get,
|
17
|
-
path: '/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
|
18
|
-
headers: {} ).
|
19
|
-
will_respond_with(
|
20
|
-
headers: pact_broker_response_headers,
|
21
|
-
status: 200,
|
22
|
-
body: pact_hash
|
23
|
-
)
|
24
|
-
end
|
25
|
-
it "returns the pact json" do
|
26
|
-
response = pact_broker_client.pacticipants.versions.pacts.get consumer: 'Condor', provider: 'Pricing Service', consumer_version: '1.3.0'
|
27
|
-
expect(response).to eq(pact_json)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "finding the latest version" do
|
32
|
-
context "when a pact is found" do
|
33
|
-
|
34
|
-
let(:response_headers) do
|
35
|
-
pact_broker_response_headers.merge(
|
36
|
-
'Content-Type' => Pact.term(generate: 'application/hal+json', matcher: %r{application/.*json}),
|
37
|
-
'X-Pact-Consumer-Version' => consumer_version
|
38
|
-
)
|
39
|
-
end
|
40
|
-
before do
|
41
|
-
pact_broker.
|
42
|
-
given("a pact between Condor and the Pricing Service exists").
|
43
|
-
upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
|
44
|
-
with(
|
45
|
-
method: :get,
|
46
|
-
path: '/pacts/provider/Pricing%20Service/consumer/Condor/latest',
|
47
|
-
headers: {}
|
48
|
-
).
|
49
|
-
will_respond_with(
|
50
|
-
status: 200,
|
51
|
-
headers: response_headers,
|
52
|
-
body: pact_hash
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns the pact json" do
|
57
|
-
response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service'
|
58
|
-
expect(response).to eq(pact_json)
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
context "when no pact is found" do
|
63
|
-
before do
|
64
|
-
pact_broker.
|
65
|
-
given("no pact between Condor and the Pricing Service exists").
|
66
|
-
upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
|
67
|
-
with(
|
68
|
-
method: :get,
|
69
|
-
path: '/pacts/provider/Pricing%20Service/consumer/Condor/latest',
|
70
|
-
headers: {}
|
71
|
-
).
|
72
|
-
will_respond_with(
|
73
|
-
status: 404
|
74
|
-
)
|
75
|
-
end
|
76
|
-
it "returns nil" do
|
77
|
-
response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service'
|
78
|
-
expect(response).to eq(nil)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
describe "finding the latest production version" do
|
83
|
-
context "when a pact is found" do
|
84
|
-
before do
|
85
|
-
pact_broker.
|
86
|
-
given("a pact between Condor and the Pricing Service exists for the production version of Condor").
|
87
|
-
upon_receiving("a request to retrieve the pact between the production verison of Condor and the Pricing Service").
|
88
|
-
with(
|
89
|
-
method: :get,
|
90
|
-
path: '/pacts/provider/Pricing%20Service/consumer/Condor/latest/prod',
|
91
|
-
headers: { 'Accept' => 'application/hal+json, application/json'}
|
92
|
-
).
|
93
|
-
will_respond_with(
|
94
|
-
status: 200,
|
95
|
-
body: pact_hash,
|
96
|
-
headers: pact_broker_response_headers
|
97
|
-
)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "returns the pact json" do
|
101
|
-
response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service', tag: 'prod'
|
102
|
-
expect(response).to eq(pact_json)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact_broker/client'
|
3
|
-
require_relative 'pact_helper'
|
4
|
-
|
5
|
-
describe PactBroker::Client::Versions, pact: true do
|
6
|
-
|
7
|
-
include_context "pact broker"
|
8
|
-
|
9
|
-
describe "tagging a version with prod details" do
|
10
|
-
let(:repository_ref) { "packages/condor-#{version}" }
|
11
|
-
|
12
|
-
let(:tag_options) { {pacticipant: 'Condor', version: version, repository_ref: repository_ref, :tag => 'prod'} }
|
13
|
-
context "when the component exists" do
|
14
|
-
before do
|
15
|
-
pact_broker.
|
16
|
-
given("'Condor' exists in the pact-broker").
|
17
|
-
upon_receiving("a request to tag the production version of Condor").
|
18
|
-
with(
|
19
|
-
method: :put,
|
20
|
-
path: '/pacticipants/Condor/versions/1.3.0/tags/prod',
|
21
|
-
headers: default_request_headers).
|
22
|
-
will_respond_with(
|
23
|
-
status: 201,
|
24
|
-
headers: pact_broker_response_headers,
|
25
|
-
body: {
|
26
|
-
_links: {
|
27
|
-
self: {
|
28
|
-
href:
|
29
|
-
Pact::Term.new(
|
30
|
-
generate: 'http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod',
|
31
|
-
matcher: %r{http://.*/pacticipants/Condor/versions/1.3.0/tags/prod})
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
)
|
36
|
-
end
|
37
|
-
it "returns true" do
|
38
|
-
expect(pact_broker_client.pacticipants.versions.tag tag_options).to be true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
context "when the component does not exist" do
|
42
|
-
before do
|
43
|
-
pact_broker.
|
44
|
-
given("'Condor' does not exist in the pact-broker").
|
45
|
-
upon_receiving("a request to tag the production version of Condor").
|
46
|
-
with(
|
47
|
-
method: :put,
|
48
|
-
path: '/pacticipants/Condor/versions/1.3.0/tags/prod',
|
49
|
-
headers: default_request_headers).
|
50
|
-
will_respond_with(
|
51
|
-
status: 201,
|
52
|
-
headers: pact_broker_response_headers,
|
53
|
-
body: {
|
54
|
-
_links: {
|
55
|
-
self: {
|
56
|
-
href:
|
57
|
-
Pact::Term.new(
|
58
|
-
generate: 'http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod',
|
59
|
-
matcher: %r{http://.*/pacticipants/Condor/versions/1.3.0/tags/prod})
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
)
|
64
|
-
end
|
65
|
-
it "returns true" do
|
66
|
-
expect(pact_broker_client.pacticipants.versions.tag tag_options).to be true
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "when the tag already exists" do
|
71
|
-
before do
|
72
|
-
pact_broker.
|
73
|
-
given("'Condor' exists in the pact-broker with version 1.3.0, tagged with 'prod'").
|
74
|
-
upon_receiving("a request to tag the production version of Condor").
|
75
|
-
with(
|
76
|
-
method: :put,
|
77
|
-
path: '/pacticipants/Condor/versions/1.3.0/tags/prod',
|
78
|
-
headers: default_request_headers).
|
79
|
-
will_respond_with(
|
80
|
-
status: 200,
|
81
|
-
headers: pact_broker_response_headers,
|
82
|
-
body: {
|
83
|
-
_links: {
|
84
|
-
self: {
|
85
|
-
href:
|
86
|
-
Pact::Term.new(
|
87
|
-
generate: 'http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod',
|
88
|
-
matcher: %r{http://.*/pacticipants/Condor/versions/1.3.0/tags/prod})
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "returns true" do
|
96
|
-
expect(pact_broker_client.pacticipants.versions.tag tag_options).to be true
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
require_relative 'pact_helper'
|
2
|
-
require 'pact_broker/client'
|
3
|
-
|
4
|
-
describe PactBroker::Client::Versions, pact: true do
|
5
|
-
|
6
|
-
include_context "pact broker"
|
7
|
-
|
8
|
-
let(:get_headers) { { "Accept" => "application/hal+json, application/json" } }
|
9
|
-
|
10
|
-
describe "retrieving the latest pacticipant version" do
|
11
|
-
let(:latest_version_path) { "/HAL-REL-PLACEHOLDER-INDEX-PB-LATEST-VERSION-{pacticipant}" }
|
12
|
-
let(:latest_version_url) { pact_broker.mock_service_base_url + latest_version_path }
|
13
|
-
|
14
|
-
before do
|
15
|
-
pact_broker
|
16
|
-
.given("the pb:latest-version relation exists in the index resource")
|
17
|
-
.upon_receiving("a request for the index resource")
|
18
|
-
.with(
|
19
|
-
method: :get,
|
20
|
-
path: '/',
|
21
|
-
headers: get_headers).
|
22
|
-
will_respond_with(
|
23
|
-
status: 200,
|
24
|
-
headers: pact_broker_response_headers,
|
25
|
-
body: {
|
26
|
-
_links: {
|
27
|
-
:'pb:latest-version' => {
|
28
|
-
href: Pact.term(latest_version_url, /http:\/\/.*{pacticipant}/)
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
)
|
33
|
-
|
34
|
-
pact_broker
|
35
|
-
.given("'Condor' exists in the pact-broker with the latest version 1.2.3")
|
36
|
-
.upon_receiving("a request to retrieve the latest version of Condor")
|
37
|
-
.with(
|
38
|
-
method: :get,
|
39
|
-
path: '/HAL-REL-PLACEHOLDER-INDEX-PB-LATEST-VERSION-Condor',
|
40
|
-
headers: get_headers).
|
41
|
-
will_respond_with(
|
42
|
-
status: 200,
|
43
|
-
headers: pact_broker_response_headers,
|
44
|
-
body: {
|
45
|
-
number: '1.2.3',
|
46
|
-
_links: {
|
47
|
-
self: {
|
48
|
-
href: Pact.term('http://localhost:1234/some-url', %r{http://.*})
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "returns the version hash" do
|
56
|
-
version_hash = pact_broker_client.pacticipants.versions.latest(pacticipant: 'Condor')
|
57
|
-
expect(version_hash[:number]).to eq '1.2.3'
|
58
|
-
expect(version_hash[:_links][:self][:href]).to eq 'http://localhost:1234/some-url'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "retrieving the latest pacticipant version for a tag" do
|
63
|
-
let(:latest_tagged_version_path) { "/HAL-REL-PLACEHOLDER-INDEX-PB-LATEST-TAGGED-VERSION-{pacticipant}-{tag}" }
|
64
|
-
let(:latest_tagged_version_url) { pact_broker.mock_service_base_url + latest_tagged_version_path }
|
65
|
-
|
66
|
-
before do
|
67
|
-
pact_broker
|
68
|
-
.given("the pb:latest-tagged-version relation exists in the index resource")
|
69
|
-
.upon_receiving("a request for the index resource")
|
70
|
-
.with(
|
71
|
-
method: :get,
|
72
|
-
path: '/',
|
73
|
-
headers: get_headers).
|
74
|
-
will_respond_with(
|
75
|
-
status: 200,
|
76
|
-
headers: pact_broker_response_headers,
|
77
|
-
body: {
|
78
|
-
_links: {
|
79
|
-
:'pb:latest-tagged-version' => {
|
80
|
-
href: Pact.term(latest_tagged_version_url, /http:\/\/.*{pacticipant}.*{tag}/)
|
81
|
-
}
|
82
|
-
}
|
83
|
-
}
|
84
|
-
)
|
85
|
-
|
86
|
-
pact_broker
|
87
|
-
.given("'Condor' exists in the pact-broker with the latest tagged 'production' version 1.2.3")
|
88
|
-
.upon_receiving("a request to retrieve the latest 'production' version of Condor")
|
89
|
-
.with(
|
90
|
-
method: :get,
|
91
|
-
path: '/HAL-REL-PLACEHOLDER-INDEX-PB-LATEST-TAGGED-VERSION-Condor-production',
|
92
|
-
headers: get_headers).
|
93
|
-
will_respond_with(
|
94
|
-
status: 200,
|
95
|
-
headers: pact_broker_response_headers,
|
96
|
-
body: {
|
97
|
-
number: '1.2.3',
|
98
|
-
_links: {
|
99
|
-
self: {
|
100
|
-
href: Pact.term('http://localhost:1234/some-url', %r{http://.*})
|
101
|
-
}
|
102
|
-
}
|
103
|
-
}
|
104
|
-
)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns the version hash" do
|
108
|
-
version_hash = pact_broker_client.pacticipants.versions.latest(pacticipant: 'Condor', tag: 'production')
|
109
|
-
expect(version_hash[:number]).to eq '1.2.3'
|
110
|
-
expect(version_hash[:_links][:self][:href]).to eq 'http://localhost:1234/some-url'
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/consumer/rspec'
|
3
|
-
|
4
|
-
|
5
|
-
Pact.configure do | config |
|
6
|
-
config.logger.level = Logger::DEBUG
|
7
|
-
config.doc_generator = :markdown
|
8
|
-
end
|
9
|
-
|
10
|
-
Pact.service_consumer 'Pact Broker Client' do
|
11
|
-
has_pact_with "Pact Broker" do
|
12
|
-
mock_service :pact_broker do
|
13
|
-
port 1234
|
14
|
-
pact_specification_version "2.0"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
has_pact_with "PactFlow" do
|
19
|
-
mock_service :pactflow do
|
20
|
-
port 1235
|
21
|
-
pact_specification_version "2.0"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module PactBrokerPactHelperMethods
|
27
|
-
|
28
|
-
# Use this for the path in the Pact request expectation.
|
29
|
-
# @param [String] relation eg "pb:pacticipant"
|
30
|
-
# @param [Array<String>] params eg ["Foo"]
|
31
|
-
def placeholder_path(relation, params = [])
|
32
|
-
path = "/HAL-REL-PLACEHOLDER-#{relation.gsub(':', '-').upcase}"
|
33
|
-
if params.any?
|
34
|
-
joined_params = params.join("-")
|
35
|
-
path = "#{path}-#{joined_params}"
|
36
|
-
end
|
37
|
-
|
38
|
-
path
|
39
|
-
end
|
40
|
-
|
41
|
-
def placeholder_url(relation, params = [], mock_service = pact_broker)
|
42
|
-
"#{mock_service.mock_service_base_url}#{placeholder_path_for_term(relation, params)}"
|
43
|
-
end
|
44
|
-
|
45
|
-
# @param [String] relation eg "pb:pacticipants"
|
46
|
-
# @param [Array<String>] params eg ["pacticipant"]
|
47
|
-
def placeholder_path_for_term(relation, params = [])
|
48
|
-
path = "/HAL-REL-PLACEHOLDER-#{relation.gsub(':', '-').upcase}"
|
49
|
-
if params.any?
|
50
|
-
joined_params = params.collect{ |param| "{#{param}}"}.join("-")
|
51
|
-
path = "#{path}-#{joined_params}"
|
52
|
-
end
|
53
|
-
|
54
|
-
path
|
55
|
-
end
|
56
|
-
|
57
|
-
def placeholder_url_term(relation, params = [], mock_service = pact_broker)
|
58
|
-
regexp = "http:\/\/.*"
|
59
|
-
if params.any?
|
60
|
-
joined_params_for_regexp = params.collect{ |param| "{#{param}}"}.join(".*")
|
61
|
-
regexp = "#{regexp}#{joined_params_for_regexp}"
|
62
|
-
end
|
63
|
-
|
64
|
-
Pact.term(placeholder_url(relation, params, mock_service), /#{regexp}/)
|
65
|
-
end
|
66
|
-
|
67
|
-
def mock_pact_broker_index(context, mock_service = pact_broker)
|
68
|
-
mock_service
|
69
|
-
.upon_receiving("a request for the index resource")
|
70
|
-
.with(
|
71
|
-
method: :get,
|
72
|
-
path: '/',
|
73
|
-
headers: context.get_request_headers).
|
74
|
-
will_respond_with(
|
75
|
-
status: 200,
|
76
|
-
headers: context.pact_broker_response_headers,
|
77
|
-
body: {
|
78
|
-
_links: {
|
79
|
-
:'pb:webhooks' => {
|
80
|
-
href: placeholder_url_term('pb:webhooks', [], mock_service)
|
81
|
-
},
|
82
|
-
:'pb:pacticipants' => {
|
83
|
-
href: placeholder_url_term('pb:pacticipants', [], mock_service)
|
84
|
-
},
|
85
|
-
:'pb:pacticipant' => {
|
86
|
-
href: placeholder_url_term('pb:pacticipant', ['pacticipant'], mock_service)
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
def mock_pact_broker_index_with_relations(context, links, provider_state)
|
94
|
-
_links = links.each_with_object({}) do | (key, value), new_links |
|
95
|
-
new_links[key] = {
|
96
|
-
href: value
|
97
|
-
}
|
98
|
-
end
|
99
|
-
|
100
|
-
pact_broker
|
101
|
-
.given(provider_state)
|
102
|
-
.upon_receiving("a request for the index resource")
|
103
|
-
.with(
|
104
|
-
method: :get,
|
105
|
-
path: '/',
|
106
|
-
headers: context.get_request_headers).
|
107
|
-
will_respond_with(
|
108
|
-
status: 200,
|
109
|
-
headers: context.pact_broker_response_headers,
|
110
|
-
body: {
|
111
|
-
_links: _links
|
112
|
-
}
|
113
|
-
)
|
114
|
-
end
|
115
|
-
|
116
|
-
def mock_pact_broker_index_with_webhook_relation(context)
|
117
|
-
pact_broker
|
118
|
-
.upon_receiving("a request for the index resource with the webhook relation")
|
119
|
-
.with(
|
120
|
-
method: :get,
|
121
|
-
path: '/',
|
122
|
-
headers: context.get_request_headers).
|
123
|
-
will_respond_with(
|
124
|
-
status: 200,
|
125
|
-
headers: context.pact_broker_response_headers,
|
126
|
-
body: {
|
127
|
-
_links: {
|
128
|
-
:'pb:webhook' => {
|
129
|
-
href: Pact.term(pact_broker.mock_service_base_url + "/webhooks/{uuid}", %r{http://.*/webhooks/{uuid}}),
|
130
|
-
templated: true
|
131
|
-
}
|
132
|
-
}
|
133
|
-
}
|
134
|
-
)
|
135
|
-
end
|
136
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
require_relative "pact_helper"
|
3
|
-
require "pactflow/client/provider_contracts/publish"
|
4
|
-
|
5
|
-
RSpec.describe "publishing a provider contract to PactFlow", pact: true do
|
6
|
-
before do
|
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
|
-
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
|
-
build_url: "http://build",
|
21
|
-
contract: {
|
22
|
-
content: { "some" => "contract" }.to_yaml,
|
23
|
-
content_type: "application/yaml",
|
24
|
-
specification: "oas"
|
25
|
-
},
|
26
|
-
verification_results: {
|
27
|
-
success: true,
|
28
|
-
content: "some results",
|
29
|
-
content_type: "text/plain",
|
30
|
-
format: "text",
|
31
|
-
verifier: "my custom tool",
|
32
|
-
verifier_version: "1.0"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:request_body) do
|
38
|
-
{
|
39
|
-
"pacticipantVersionNumber" => "1",
|
40
|
-
"tags" => ["dev"],
|
41
|
-
"branch" => "main",
|
42
|
-
"buildUrl" => "http://build",
|
43
|
-
"contract" => {
|
44
|
-
"content" => "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
|
45
|
-
"contentType" => "application/yaml",
|
46
|
-
"specification" => "oas",
|
47
|
-
"selfVerificationResults" => {
|
48
|
-
"success" => true,
|
49
|
-
"content" => "c29tZSByZXN1bHRz",
|
50
|
-
"contentType" => "text/plain",
|
51
|
-
"format" => "text",
|
52
|
-
"verifier" => "my custom tool",
|
53
|
-
"verifierVersion" => "1.0"
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
let(:response_status) { 200 }
|
60
|
-
|
61
|
-
# Can't tell from the response if the buildUrl was correct, but it's not that important
|
62
|
-
# Add some assertions to the body to ensure we have called the endpoint correctly,
|
63
|
-
# not because we use the properties in the CLI output.
|
64
|
-
# There is unfortunately no good way to determine from the response whether or not
|
65
|
-
# we have correctly published the self verification results.
|
66
|
-
let(:success_response) do
|
67
|
-
{
|
68
|
-
status: response_status,
|
69
|
-
headers: pact_broker_response_headers,
|
70
|
-
body: {
|
71
|
-
"notices" => Pact.each_like("text" => "some notice", "type" => "info"),
|
72
|
-
"_embedded" => {
|
73
|
-
"version" => {
|
74
|
-
# This tells us we have set the version number correctly
|
75
|
-
"number" => "1"
|
76
|
-
}
|
77
|
-
},
|
78
|
-
"_links" => {
|
79
|
-
# The links tell us we have successfully created the tags, but we don't care about the contents
|
80
|
-
"pb:pacticipant-version-tags" => [{}],
|
81
|
-
# The link tells us we have successfully created the branch version, but we don't care about the contents
|
82
|
-
"pb:branch-version" => {},
|
83
|
-
}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
let(:options) do
|
89
|
-
{
|
90
|
-
verbose: false
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
let(:pact_broker_client_options) do
|
95
|
-
{ pact_broker_base_url: pactflow.mock_service_base_url }
|
96
|
-
end
|
97
|
-
|
98
|
-
subject { Pactflow::Client::ProviderContracts::Publish.call(command_params, options, pact_broker_client_options) }
|
99
|
-
|
100
|
-
context "creating a provider contract with valid parameters" do
|
101
|
-
before do
|
102
|
-
pactflow
|
103
|
-
.given("the pb:publish-provider-contract relation exists in the index resource")
|
104
|
-
.upon_receiving("a request for the index resource")
|
105
|
-
.with(
|
106
|
-
method: "GET",
|
107
|
-
path: "/",
|
108
|
-
headers: get_request_headers
|
109
|
-
).will_respond_with(
|
110
|
-
status: 200,
|
111
|
-
headers: pact_broker_response_headers,
|
112
|
-
body: {
|
113
|
-
_links: {
|
114
|
-
:'pf:publish-provider-contract' => {
|
115
|
-
href: placeholder_url_term("pf:publish-provider-contract", ['provider'], pactflow)
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
)
|
120
|
-
|
121
|
-
pactflow
|
122
|
-
.upon_receiving("a request to publish a provider contract")
|
123
|
-
.with(
|
124
|
-
method: :post,
|
125
|
-
path: placeholder_path("pf:publish-provider-contract", ["Bar"]),
|
126
|
-
headers: post_request_headers.merge("Accept" => "application/hal+json,application/problem+json"),
|
127
|
-
body: request_body
|
128
|
-
).will_respond_with(success_response)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "returns a CommandResult with success = true" do
|
132
|
-
expect(subject).to be_a PactBroker::Client::CommandResult
|
133
|
-
expect(subject.success).to be true
|
134
|
-
expect(subject.message).to include "some notice"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|