pact_broker-client 1.43.0 → 1.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +21 -0
  3. data/CHANGELOG.md +13 -0
  4. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +0 -281
  5. data/lib/pact_broker/client/cli/broker.rb +3 -55
  6. data/lib/pact_broker/client/cli/deployment_commands.rb +74 -0
  7. data/lib/pact_broker/client/cli/pacticipant_commands.rb +9 -0
  8. data/lib/pact_broker/client/deployments.rb +4 -0
  9. data/lib/pact_broker/client/deployments/record_deployment.rb +38 -0
  10. data/lib/pact_broker/client/deployments/record_release.rb +99 -0
  11. data/lib/pact_broker/client/deployments/record_undeployment.rb +120 -0
  12. data/lib/pact_broker/client/describe_text_formatter.rb +23 -0
  13. data/lib/pact_broker/client/environments.rb +6 -3
  14. data/lib/pact_broker/client/environments/describe_environment.rb +3 -13
  15. data/lib/pact_broker/client/hal/entity.rb +5 -2
  16. data/lib/pact_broker/client/hal/http_client.rb +3 -2
  17. data/lib/pact_broker/client/pacticipants.rb +3 -3
  18. data/lib/pact_broker/client/pacticipants/create.rb +1 -1
  19. data/lib/pact_broker/client/pacticipants/describe.rb +33 -0
  20. data/lib/pact_broker/client/version.rb +1 -1
  21. data/lib/pact_broker/client/versions.rb +4 -1
  22. data/lib/pact_broker/client/versions/describe.rb +3 -1
  23. data/lib/pact_broker/client/versions/formatter.rb +3 -1
  24. data/lib/pact_broker/client/versions/json_formatter.rb +5 -3
  25. data/lib/pact_broker/client/versions/text_formatter.rb +3 -1
  26. data/script/record-deployments-and-releases.sh +10 -0
  27. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
  28. data/spec/integration/describe_environment_spec.rb +31 -0
  29. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -0
  30. data/spec/pacts/pact_broker_client-pact_broker.json +0 -288
  31. data/spec/service_providers/publish_pacts_spec.rb +3 -1
  32. data/spec/service_providers/record_deployment_spec.rb +7 -29
  33. data/spec/service_providers/record_release_spec.rb +135 -0
  34. data/spec/spec_helper.rb +13 -2
  35. data/tasks/pact.rake +19 -1
  36. metadata +18 -6
  37. data/lib/pact_broker/client/versions/record_deployment.rb +0 -85
  38. data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
  39. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -75
@@ -1,102 +0,0 @@
1
- require 'pact_broker/client/hal_client_methods'
2
- require 'pact_broker/client/error'
3
- require 'pact_broker/client/command_result'
4
-
5
- # TODO
6
- # --limit 1
7
- # order by date so that the oldest one gets undeployed first
8
-
9
- module PactBroker
10
- module Client
11
- class Versions
12
- class RecordUndeployment
13
- include PactBroker::Client::HalClientMethods
14
-
15
- NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support recording undeployments. Please upgrade to version 2.80.0 or later."
16
-
17
- def self.call(params, pact_broker_base_url, pact_broker_client_options)
18
- new(params, pact_broker_base_url, pact_broker_client_options).call
19
- end
20
-
21
- def initialize(params, pact_broker_base_url, pact_broker_client_options)
22
- @pact_broker_base_url = pact_broker_base_url
23
- @pacticipant_name = params.fetch(:pacticipant_name)
24
- @version_number = params.fetch(:version_number)
25
- @environment_name = params.fetch(:environment_name)
26
- @output = params.fetch(:output)
27
- @pact_broker_client_options = pact_broker_client_options
28
- end
29
-
30
- def call
31
- check_if_command_supported
32
- if deployed_version_links_for_environment.any?
33
- @undeployment_entities = deployed_version_links_for_environment.collect do | deployed_version_link |
34
- deployed_version_link.get!._link!("pb:record-undeployment").post!
35
- end
36
- else
37
- check_environment_exists
38
- raise_not_found_error
39
- end
40
-
41
- PactBroker::Client::CommandResult.new(true, "foo")
42
- rescue PactBroker::Client::Error => e
43
- PactBroker::Client::CommandResult.new(false, e.message)
44
- end
45
-
46
- private
47
-
48
- attr_reader :pact_broker_base_url, :pact_broker_client_options
49
- attr_reader :pacticipant_name, :version_number, :environment_name, :target, :output
50
- attr_reader :deployed_version_resource, :undeployment_entities
51
-
52
- def version_resource
53
- index_resource._link!("pb:pacticipant-version").expand(pacticipant: pacticipant_name, version: version_number).get!
54
- end
55
-
56
- def deployed_version_links
57
- @deployed_version_links ||= version_resource._links!("pb:currently-deployed-versions")
58
- end
59
-
60
- def deployed_version_links_for_environment
61
- @deployed_version_links_for_environment ||= deployed_version_links.select(environment_name)
62
- end
63
-
64
- def check_environment_exists
65
- index_resource
66
- ._link!("pb:environments")
67
- .get!
68
- ._links("pb:environments")
69
- .find!(environment_name, "No environment found with name '#{environment_name}'")
70
- end
71
-
72
- def raise_not_found_error
73
- raise PactBroker::Client::Error.new(deployed_version_not_found_message)
74
- end
75
-
76
- def deployed_version_not_found_message
77
- if (env_names = deployed_version_links.names).any?
78
- "#{pacticipant_name} version #{version_number} is not currently deployed to #{environment_name}. It is currently deployed to: #{env_names.join(", ")}"
79
- else
80
- "#{pacticipant_name} version #{version_number} is not currently deployed to any environment."
81
- end
82
- end
83
-
84
- def result_message
85
- if output == "text"
86
- message = "Recorded undeployment of #{pacticipant_name} version #{version_number} from #{environment_name} in #{pact_broker_name}."
87
- elsif output == "json"
88
- undeployment_entities.last.response.raw_body
89
- else
90
- ""
91
- end
92
- end
93
-
94
- def check_if_command_supported
95
- unless index_resource.can?("pb:environments")
96
- raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
97
- end
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,75 +0,0 @@
1
- require 'pact_broker/client/versions/record_deployment'
2
-
3
- module PactBroker
4
- module Client
5
- class Versions
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
- }
13
- end
14
- let!(:index_request) do
15
- stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
16
- end
17
-
18
- let(:target) { "blue" }
19
-
20
- let(:params) do
21
- {
22
- pacticipant_name: "Foo",
23
- version_number: "1",
24
- environment_name: "test",
25
- target: target
26
- }
27
- end
28
-
29
- let(:options) do
30
- {
31
- output: "text"
32
- }
33
- end
34
- let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url} }
35
-
36
- subject { RecordDeployment.call(params, options, pact_broker_client_options) }
37
-
38
- context "when the pb:environments relation does not exist" do
39
- it "returns an error response" do
40
- expect(subject.success).to be false
41
- expect(subject.message).to include "does not support"
42
- end
43
- end
44
-
45
- context "when the response headers contain Pactflow" do
46
- before do
47
- allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
48
- allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
49
- allow_any_instance_of(RecordDeployment).to receive(:record_deployment)
50
- allow_any_instance_of(RecordDeployment).to receive(:index_resource).and_return(index_resource)
51
- end
52
-
53
- let(:response_headers) { { "X-Pactflow-Sha" => "abc" } }
54
-
55
- let(:index_resource) do
56
- double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
57
- end
58
-
59
- it "indicates the API was Pactflow" do
60
- expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment (target blue) in Pactflow"
61
- end
62
-
63
- context "when target is nil" do
64
- let(:target) { nil }
65
-
66
- it "does not include the target in the result message" do
67
- expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment in"
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end