pact_broker-client 1.75.3 → 1.75.4

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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/pact_broker/client/version.rb +1 -1
  4. metadata +5 -216
  5. data/.github/workflows/test.yml +0 -59
  6. data/.rspec +0 -3
  7. data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
  8. data/lib/pact_broker/client/webhooks/test.rb +0 -16
  9. data/pact-broker-client.gemspec +0 -31
  10. data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
  11. data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
  12. data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
  13. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
  14. data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
  15. data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
  16. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
  17. data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
  18. data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
  19. data/spec/fixtures/certificates/ca_cert.pem +0 -19
  20. data/spec/fixtures/certificates/ca_cert.srl +0 -1
  21. data/spec/fixtures/certificates/ca_key.pem +0 -28
  22. data/spec/fixtures/certificates/client_cert.pem +0 -17
  23. data/spec/fixtures/certificates/key.pem +0 -28
  24. data/spec/fixtures/certificates/server.csr +0 -15
  25. data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
  26. data/spec/fixtures/certificates/unsigned_key.pem +0 -28
  27. data/spec/fixtures/foo-bar.json +0 -31
  28. data/spec/integration/can_i_deploy_spec.rb +0 -24
  29. data/spec/integration/can_i_merge_spec.rb +0 -44
  30. data/spec/integration/create_version_tag_spec.rb +0 -20
  31. data/spec/integration/describe_environment_spec.rb +0 -31
  32. data/spec/integration/publish_provider_contract_spec.rb +0 -53
  33. data/spec/integration/unknown_options_spec.rb +0 -39
  34. data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
  35. data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
  36. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
  37. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
  38. data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
  39. data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
  40. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
  41. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
  42. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
  43. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
  44. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
  45. data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
  46. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
  47. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
  48. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
  49. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
  50. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
  51. data/spec/lib/pact_broker/client/git_spec.rb +0 -159
  52. data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
  53. data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
  54. data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
  55. data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
  56. data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
  57. data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
  58. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
  59. data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
  60. data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
  61. data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
  62. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
  63. data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
  64. data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
  65. data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
  66. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
  67. data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
  68. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
  69. data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
  70. data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
  71. data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
  72. data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
  73. data/spec/pacts/pact_broker_client-pactflow.json +0 -288
  74. data/spec/readme_spec.rb +0 -16
  75. data/spec/service_providers/create_environment_spec.rb +0 -78
  76. data/spec/service_providers/delete_branch_spec.rb +0 -68
  77. data/spec/service_providers/extra_goodies_spec.rb +0 -108
  78. data/spec/service_providers/list_environments_spec.rb +0 -77
  79. data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
  80. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
  81. data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
  82. data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
  83. data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
  84. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
  85. data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
  86. data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
  87. data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
  88. data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
  89. data/spec/service_providers/pact_helper.rb +0 -136
  90. data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
  91. data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
  92. data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
  93. data/spec/service_providers/pacticipants_create_spec.rb +0 -119
  94. data/spec/service_providers/publish_pacts_spec.rb +0 -114
  95. data/spec/service_providers/record_deployment_spec.rb +0 -199
  96. data/spec/service_providers/record_release_spec.rb +0 -130
  97. data/spec/service_providers/record_undeployment_spec.rb +0 -164
  98. data/spec/service_providers/webhooks_create_spec.rb +0 -391
  99. data/spec/spec_helper.rb +0 -68
  100. data/spec/support/approvals.rb +0 -26
  101. data/spec/support/cli_test_pacts/bar.json +0 -0
  102. data/spec/support/cli_test_pacts/foo.json +0 -0
  103. data/spec/support/latest_pacts_for_provider.json +0 -15
  104. data/spec/support/matrix.json +0 -35
  105. data/spec/support/matrix.txt +0 -3
  106. data/spec/support/matrix_error.txt +0 -3
  107. data/spec/support/matrix_with_results.txt +0 -10
  108. data/spec/support/pacticipant_get.json +0 -18
  109. data/spec/support/pacticipants_list.json +0 -26
  110. data/spec/support/pacts_latest_list.json +0 -41
  111. data/spec/support/shared_context.rb +0 -25
  112. data/spec/support/ssl_server.rb +0 -42
@@ -1,129 +0,0 @@
1
- require_relative "pact_helper"
2
- require "yaml"
3
- require "pactflow/client/provider_contracts/publish_the_old_way"
4
- require "pact_broker/client/versions/create"
5
-
6
-
7
- RSpec.describe "publishing a provider contract to PactFlow the old way", pact: true do
8
- before do
9
- # no point re-testing this
10
- allow(PactBroker::Client::Versions::Create).to receive(:call).and_return(double("result", success: true))
11
- end
12
-
13
- include_context "pact broker"
14
- include PactBrokerPactHelperMethods
15
-
16
- let(:command_params) do
17
- {
18
- provider_name: "Bar",
19
- provider_version_number: "1",
20
- branch_name: "main",
21
- tags: ["dev"],
22
- contract: {
23
- content: { "some" => "contract" }.to_yaml,
24
- content_type: "application/yaml",
25
- specification: "oas"
26
- },
27
- verification_results: {
28
- success: true,
29
- content: "some results",
30
- content_type: "text/plain",
31
- format: "text",
32
- verifier: "my custom tool",
33
- verifier_version: "1.0"
34
- }
35
- }
36
- end
37
-
38
- let(:body) { { some: "body" }.to_json }
39
-
40
- let(:request_body) do
41
- {
42
- "content" => "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
43
- "contractType" => "oas",
44
- "contentType" => "application/yaml",
45
- "verificationResults" => {
46
- "success" => true,
47
- "content" => "c29tZSByZXN1bHRz",
48
- "contentType" => "text/plain",
49
- "format" => "text",
50
- "verifier" => "my custom tool",
51
- "verifierVersion" => "1.0"
52
- }
53
- }
54
- end
55
-
56
- let(:response_status) { 201 }
57
- let(:success_response) do
58
- {
59
- status: response_status,
60
- headers: pact_broker_response_headers
61
- }
62
- end
63
-
64
- let(:options) do
65
- {
66
- verbose: false
67
- }
68
- end
69
-
70
- let(:pact_broker_client_options) do
71
- { pact_broker_base_url: pactflow.mock_service_base_url }
72
- end
73
-
74
- subject { Pactflow::Client::ProviderContracts::PublishTheOldWay.call(command_params, options, pact_broker_client_options) }
75
-
76
- context "creating a provider contract with valid parameters" do
77
- before do
78
- pactflow
79
- .upon_receiving("a request to create a provider contract")
80
- .with(
81
- method: :put,
82
- path: "/contracts/provider/Bar/version/1",
83
- headers: put_request_headers,
84
- body: request_body)
85
- .will_respond_with(success_response)
86
- end
87
-
88
- it "returns a CommandResult with success = true" do
89
- expect(subject).to be_a PactBroker::Client::CommandResult
90
- expect(subject.success).to be true
91
- expect(subject.message).to include "Successfully published provider contract for Bar version 1"
92
- expect(subject.message).not_to include pactflow.mock_service_base_url
93
- end
94
- end
95
-
96
- context "creating a provider contract with valid parameters with pf:ui return results" do
97
- let(:success_response_with_pf_ui_url) do
98
- {
99
- status: response_status,
100
- headers: pact_broker_response_headers,
101
- body: { "_links": {
102
- "pf:ui": {
103
- "href": Pact.like("some-url")
104
- }
105
- } }
106
- }
107
- end
108
- before do
109
- pactflow
110
- .given("there is a pf:ui href in the response")
111
- .upon_receiving("a request to create a provider contract")
112
- .with(
113
- method: :put,
114
- path: "/contracts/provider/Bar/version/1",
115
- headers: put_request_headers,
116
- body: request_body
117
- )
118
- .will_respond_with(success_response_with_pf_ui_url)
119
- end
120
-
121
- it "returns a CommandResult with success = true and a provider contract ui url" do
122
- expect(subject).to be_a PactBroker::Client::CommandResult
123
- expect(subject.success).to be true
124
- expect(subject.message).to include "Successfully published provider contract for Bar version 1"
125
- expect(subject.message).to include "Next steps:"
126
- expect(subject.message).to include "some-url"
127
- end
128
- end
129
- end
@@ -1,86 +0,0 @@
1
- require_relative 'pact_helper'
2
- require 'pact_broker/client/webhooks/create'
3
-
4
- RSpec.describe "creating a webhook in PactFlow", pact: true do
5
-
6
- include_context "pact broker"
7
- include PactBrokerPactHelperMethods
8
-
9
- let(:params) do
10
- {
11
- description: "a webhook",
12
- events: %w{contract_content_changed},
13
- http_method: "POST",
14
- url: "https://webhook",
15
- headers: { "Foo" => "bar", "Bar" => "foo"},
16
- body: body,
17
- team_uuid: "2abbc12a-427d-432a-a521-c870af1739d9"
18
- }
19
- end
20
-
21
- let(:body) { { some: "body" }.to_json }
22
-
23
- let(:request_body) do
24
- {
25
- "description" => "a webhook",
26
- "events" => [
27
- "name" => "contract_content_changed"
28
- ],
29
- "request" => {
30
- "url" => "https://webhook",
31
- "method" => "POST",
32
- "headers" => {
33
- "Foo" => "bar",
34
- "Bar" => "foo"
35
- },
36
- "body" => {
37
- "some" => "body"
38
- },
39
- },
40
- "teamUuid" => "2abbc12a-427d-432a-a521-c870af1739d9"
41
- }
42
- end
43
-
44
- let(:response_status) { 201 }
45
- let(:success_response) do
46
- {
47
- status: response_status,
48
- headers: pact_broker_response_headers,
49
- body: {
50
- description: Pact.like("a webhook"),
51
- teamUuid: "2abbc12a-427d-432a-a521-c870af1739d9",
52
- _links: {
53
- self: {
54
- href: Pact.term('http://localhost:1234/some-url', %r{http://.*}),
55
- title: Pact.like("A title")
56
- }
57
- }
58
- }
59
- }
60
- end
61
-
62
- let(:pact_broker_client_options) { {} }
63
-
64
- subject { PactBroker::Client::Webhooks::Create.call(params, pactflow.mock_service_base_url, pact_broker_client_options) }
65
-
66
- context "when a valid webhook with a team specified is submitted" do
67
- before do
68
- mock_pact_broker_index(self, pactflow)
69
- pactflow
70
- .given("a team with UUID 2abbc12a-427d-432a-a521-c870af1739d9 exists")
71
- .upon_receiving("a request to create a webhook for a team")
72
- .with(
73
- method: :post,
74
- path: '/HAL-REL-PLACEHOLDER-PB-WEBHOOKS',
75
- headers: post_request_headers,
76
- body: request_body)
77
- .will_respond_with(success_response)
78
- end
79
-
80
- it "returns a CommandResult with success = true" do
81
- expect(subject).to be_a PactBroker::Client::CommandResult
82
- expect(subject.success).to be true
83
- expect(subject.message).to eq "Webhook \"a webhook\" created"
84
- end
85
- end
86
- end
@@ -1,119 +0,0 @@
1
- require_relative 'pact_helper'
2
- require 'pact_broker/client/pacticipants/create'
3
-
4
- RSpec.describe "creating or updating a pacticipant", pact: true do
5
- include_context "pact broker"
6
- include PactBrokerPactHelperMethods
7
-
8
- before do
9
- index_links = {
10
- 'pb:pacticipants' => Pact.term('http://localhost:1234/pacticipants', %r{http://.*}),
11
- 'pb:pacticipant' => Pact.term('http://localhost:1234/pacticipants/{pacticipant}', %r{http://.*\{pacticipant\}}),
12
- }
13
- mock_pact_broker_index_with_relations(self, index_links, "the pacticipant relations are present")
14
- end
15
-
16
- let(:params) do
17
- {
18
- name: "Foo",
19
- repository_url: "http://foo"
20
- }
21
- end
22
-
23
- let(:request_body) { { name: "Foo", repositoryUrl: "http://foo" } }
24
-
25
-
26
- let(:response_status) { 201 }
27
- let(:create_success_response) do
28
- {
29
- status: response_status,
30
- headers: pact_broker_response_headers,
31
- body: {
32
- name: "Foo",
33
- repositoryUrl: "http://foo",
34
- _links: {
35
- self: {
36
- href: Pact.term('http://localhost:1234/pacticipants/Foo', %r{http://.*}),
37
- }
38
- }
39
- }
40
- }
41
- end
42
-
43
- let(:get_success_response) do
44
- {
45
- status: 200,
46
- headers: pact_broker_response_headers,
47
- body: {
48
- _links: {
49
- self: {
50
- href: Pact.term('http://localhost:1234/pacticipants/Foo', %r{http://.*}),
51
- }
52
- }
53
- }
54
- }
55
- end
56
-
57
- let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url} }
58
- let(:options) { {} }
59
-
60
- subject { PactBroker::Client::Pacticipants2::Create.call(params, options, pact_broker_client_options) }
61
-
62
- context "when the pacticipant does not already exist" do
63
- before do
64
- pact_broker
65
- .upon_receiving("a request to retrieve a pacticipant")
66
- .with(
67
- method: :get,
68
- path: '/pacticipants/Foo',
69
- headers: get_request_headers)
70
- .will_respond_with(status: 404)
71
-
72
- pact_broker
73
- .upon_receiving("a request to create a pacticipant")
74
- .with(
75
- method: :post,
76
- path: '/pacticipants',
77
- headers: post_request_headers,
78
- body: request_body)
79
- .will_respond_with(create_success_response)
80
- end
81
-
82
- it "returns a CommandResult with success = true" do
83
- expect(subject).to be_a PactBroker::Client::CommandResult
84
- expect(subject.success).to be true
85
- expect(subject.message).to include "Pacticipant \"Foo\" created"
86
- end
87
- end
88
-
89
- context "when the pacticipant does already exist" do
90
- before do
91
- pact_broker
92
- .given("a pacticipant with name Foo exists")
93
- .upon_receiving("a request to retrieve a pacticipant")
94
- .with(
95
- method: :get,
96
- path: '/pacticipants/Foo',
97
- headers: get_request_headers)
98
- .will_respond_with(get_success_response)
99
-
100
- pact_broker
101
- .given("a pacticipant with name Foo exists")
102
- .upon_receiving("a request to update a pacticipant")
103
- .with(
104
- method: :patch,
105
- path: '/pacticipants/Foo',
106
- headers: post_request_headers,
107
- body: request_body)
108
- .will_respond_with(create_success_response)
109
- end
110
-
111
- let(:response_status) { 200 }
112
-
113
- it "returns a CommandResult with success = true" do
114
- expect(subject).to be_a PactBroker::Client::CommandResult
115
- expect(subject.success).to be true
116
- expect(subject.message).to include "Pacticipant \"Foo\" updated"
117
- end
118
- end
119
- end
@@ -1,114 +0,0 @@
1
- require 'pact_broker/client/publish_pacts'
2
- require 'service_providers/pact_helper'
3
-
4
- RSpec.describe "publishing contracts", pact: true do
5
- before do
6
- allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
7
- allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
8
- end
9
- include_context "pact broker"
10
- include PactBrokerPactHelperMethods
11
-
12
- let(:pacticipant_name) { "Foo" }
13
- let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
14
- let(:output) { "text" }
15
- let(:build_url) { "http://build" }
16
- let(:consumer_version_params) do
17
- {
18
- pacticipant_name: pacticipant_name,
19
- number: version_number,
20
- tags: ["dev"],
21
- branch: "main",
22
- build_url: build_url,
23
- output: output
24
- }
25
- end
26
- let(:pact_file_path_1) { "spec/fixtures/foo-bar.json" }
27
- let(:pact_file_paths) { [pact_file_path_1] }
28
- let(:options) { { merge: true } }
29
- let(:pact_broker_client_options) { {} }
30
- let(:expected_content) { Base64.strict_encode64(JSON.parse(File.read(pact_file_path_1)).to_json) }
31
- let(:request_body) do
32
- {
33
- pacticipantName: pacticipant_name,
34
- pacticipantVersionNumber: version_number,
35
- branch: "main",
36
- tags: ["dev"],
37
- buildUrl: "http://build",
38
- contracts: [
39
- {
40
- consumerName: pacticipant_name,
41
- providerName: "Bar",
42
- specification: "pact",
43
- contentType: "application/json",
44
- content: expected_content,
45
- onConflict: "merge"
46
- }
47
- ]
48
- }
49
- end
50
-
51
- subject { PactBroker::Client::PublishPacts.call(broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options) }
52
-
53
- def mock_index
54
- pact_broker
55
- .given("the pb:publish-contracts relations exists in the index resource")
56
- .upon_receiving("a request for the index resource")
57
- .with(
58
- method: "GET",
59
- path: '/',
60
- headers: get_request_headers).
61
- will_respond_with(
62
- status: 200,
63
- headers: pact_broker_response_headers,
64
- body: {
65
- _links: {
66
- :'pb:publish-contracts' => {
67
- href: placeholder_url_term("pb:publish-contracts")
68
- }
69
- }
70
- }
71
- )
72
- end
73
-
74
- def mock_contract_publication
75
- pact_broker
76
- .upon_receiving("a request to publish contracts")
77
- .with(
78
- method: "POST",
79
- path: '/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS',
80
- headers: post_request_headers,
81
- body: request_body).
82
- will_respond_with(
83
- status: 200,
84
- headers: pact_broker_response_headers,
85
- body: {
86
- _embedded: {
87
- pacticipant: {
88
- name: pacticipant_name
89
- },
90
- version: {
91
- number: version_number
92
- }
93
- },
94
- logs: Pact.each_like(level: "info", message: "some message"),
95
- _links: {
96
- :'pb:pacticipant-version-tags' => [{ name: "dev"} ],
97
- :'pb:contracts' => [{ href: Pact.like("http://some-pact") }]
98
- }
99
- }
100
- )
101
- end
102
-
103
- context "with valid params" do
104
- before do
105
- mock_index
106
- mock_contract_publication
107
- end
108
-
109
- it "returns a success result" do
110
- expect(subject.success).to be true
111
- expect(subject.message).to include "some message"
112
- end
113
- end
114
- end
@@ -1,199 +0,0 @@
1
- require 'service_providers/pact_helper'
2
- require 'pact_broker/client/deployments/record_deployment'
3
-
4
- RSpec.describe "recording a deployment", pact: true do
5
- include_context "pact broker"
6
- include PactBrokerPactHelperMethods
7
-
8
- let(:pacticipant_name) { "Foo" }
9
- let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
10
- let(:environment_name) { "test" }
11
- let(:output) { "text" }
12
- let(:application_instance) { "blue" }
13
- let(:params) do
14
- {
15
- pacticipant_name: pacticipant_name,
16
- version_number: version_number,
17
- environment_name: environment_name,
18
- application_instance: application_instance
19
- }
20
- end
21
- let(:options) do
22
- {
23
- output: output
24
- }
25
- end
26
- let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url } }
27
-
28
- subject { PactBroker::Client::Deployments::RecordDeployment.call(params, options, pact_broker_client_options) }
29
-
30
- def mock_index
31
- pact_broker
32
- .given("the pb:pacticipant-version and pb:environments relations exist in the index resource")
33
- .upon_receiving("a request for the index resource")
34
- .with(
35
- method: "GET",
36
- path: '/',
37
- headers: get_request_headers).
38
- will_respond_with(
39
- status: 200,
40
- headers: pact_broker_response_headers,
41
- body: {
42
- _links: {
43
- :'pb:pacticipant-version' => {
44
- href: placeholder_url_term("pb:pacticipant-version", ["pacticipant", "version"])
45
- },
46
- :'pb:environments' => {
47
- href: placeholder_url_term("pb:environments")
48
- }
49
- }
50
- }
51
- )
52
- end
53
-
54
- def mock_pacticipant_version_with_test_environment_available_for_deployment
55
- pact_broker
56
- .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment")
57
- .upon_receiving("a request for a pacticipant version")
58
- .with(
59
- method: "GET",
60
- path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
61
- headers: get_request_headers
62
- )
63
- .will_respond_with(
64
- status: 200,
65
- headers: pact_broker_response_headers,
66
- body: {
67
- _links: {
68
- "pb:record-deployment" => [
69
- {
70
- name: "test",
71
- href: placeholder_url_term("pb:record-deployment-#{pacticipant_name}-#{version_number}-#{environment_name}")
72
- }
73
- ]
74
- }
75
- }
76
- )
77
- end
78
-
79
- def mock_pacticipant_version_without_test_environment_available_for_deployment
80
- pact_broker
81
- .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment")
82
- .upon_receiving("a request for a pacticipant version")
83
- .with(
84
- method: "GET",
85
- path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
86
- headers: get_request_headers
87
- )
88
- .will_respond_with(
89
- status: 200,
90
- headers: pact_broker_response_headers,
91
- body: {
92
- _links: {
93
- "pb:record-deployment" => [
94
- Pact.like(
95
- name: "prod",
96
- href: "href"
97
- ),
98
- Pact.like(
99
- name: "dev",
100
- href: "href"
101
- ),
102
- ]
103
- }
104
- }
105
- )
106
- end
107
-
108
- def mock_environments
109
- pact_broker
110
- .given("an environment with name test exists")
111
- .upon_receiving("a request for the environments")
112
- .with(
113
- method: "GET",
114
- path: "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
115
- headers: get_request_headers
116
- )
117
- .will_respond_with(
118
- status: 200,
119
- headers: pact_broker_response_headers,
120
- body: {
121
- _links: {
122
- "pb:environments" => [
123
- {
124
- name: "test",
125
- href: Pact.like("href")
126
- }
127
- ]
128
- }
129
- }
130
- )
131
- end
132
-
133
- def mock_record_deployment
134
- pact_broker
135
- .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment")
136
- .upon_receiving("a request to record a deployment")
137
- .with(
138
- method: "POST",
139
- path: "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
140
- headers: post_request_headers,
141
- body: {
142
- applicationInstance: application_instance,
143
- target: application_instance
144
- }
145
- )
146
- .will_respond_with(
147
- status: 201,
148
- headers: pact_broker_response_headers,
149
- body: {
150
- target: application_instance
151
- }
152
- )
153
- end
154
-
155
- context "when the deployment is recorded successfully" do
156
- before do
157
- mock_index
158
- mock_pacticipant_version_with_test_environment_available_for_deployment
159
- mock_record_deployment
160
- end
161
-
162
- it "returns a success message" do
163
- expect(subject.success).to be true
164
- expect(subject.message).to include "Recorded deployment of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test environment (application instance blue) in the Pact Broker."
165
- end
166
-
167
- context "when the output is json" do
168
- let(:output) { "json" }
169
-
170
- it "returns the JSON payload" do
171
- expect(JSON.parse(subject.message)).to eq "target" => application_instance
172
- end
173
- end
174
- end
175
-
176
- context "when the specified environment is not available for recording a deployment" do
177
- before do
178
- mock_index
179
- mock_pacticipant_version_without_test_environment_available_for_deployment
180
- mock_environments
181
- end
182
-
183
- context "when the specified environment does not exist" do
184
- let(:environment_name) { "foo" }
185
-
186
- it "returns an error response" do
187
- expect(subject.success).to be false
188
- expect(subject.message).to include "No environment found"
189
- end
190
- end
191
-
192
- context "when the specified environment does exist" do
193
- it "returns an error response" do
194
- expect(subject.success).to be false
195
- expect(subject.message).to include "not an available option"
196
- end
197
- end
198
- end
199
- end