pact_broker-client 1.25.1 → 1.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c78c1aac0ad2d50892f581f5bf0bb77b4b73e32b1ae359ae94a62eb4d62855b
4
- data.tar.gz: 509cc602635703e5ff07520ef5b0163ff47ed4cbaadebca33de0ebced3d34bdd
3
+ metadata.gz: fa13a2780e0b74313fcd7d9384f6ddc19efec60d30d9d4ba570d74dbd695e5e7
4
+ data.tar.gz: 7f3f0cc727f250be1cf9944bbd688b8c093e0fe572af0db5cf2067ec65f7e513
5
5
  SHA512:
6
- metadata.gz: 38988ea9692c16df96c3ba1c18cbd2509286efede5b7e72d2561540ffeb78e0d5e442a83aacd26f2ca61f4939a2e4458130bcdc0f605e1711c304590f281e9e0
7
- data.tar.gz: 2efd70539e123a3b2b7ffbe7f2c691f497ba4dc1034fb25d4fd5800faa4cae50bbd2960ba3a87a149decb5127bdc7621873f51d60ab48dc988f5059bad3a6125
6
+ metadata.gz: e4841315d2119ca788c0487ed62e26e3dd76dba04e6464a592ccd5a8cb958f1ca056116f98218b3fab49e79a130755270ed3893778f4f0a23c20991f86d6260c
7
+ data.tar.gz: 20c244d83fda1e3ae2e71c87c8076d49b5628bc319d31ad150f005a777411c7a08f7ca0e24725ed98c6846ba8a88df5f449ce42dacfe2134ce429719fda0e930
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ <a name="v1.26.0"></a>
2
+ ### v1.26.0 (2020-04-17)
3
+
4
+
5
+ #### Features
6
+
7
+ * update message when waiting for verification results ([68df012](/../../commit/68df012))
8
+ * add create-or-update-pacticipant ([f1c33ae](/../../commit/f1c33ae))
9
+
10
+ * **can i deploy**
11
+ * put out a message while waiting for verification results to be published ([cc1ba5f](/../../commit/cc1ba5f))
12
+
13
+ * **publish pacts**
14
+ * improve message when overwriting pacts ([17b93f3](/../../commit/17b93f3))
15
+
16
+ * **webhooks**
17
+ * add command to test webhook execution ([0ee1f7a](/../../commit/0ee1f7a))
18
+
19
+
1
20
  <a name="v1.25.1"></a>
2
21
  ### v1.25.1 (2020-04-02)
3
22
 
@@ -22,6 +22,8 @@
22
22
 
23
23
  * [A request for the index resource](#a_request_for_the_index_resource)
24
24
 
25
+ * [A request for the index resource](#a_request_for_the_index_resource_given_the_pacticipant_relations_are_present) given the pacticipant relations are present
26
+
25
27
  * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:latest-tagged-version_relation_exists_in_the_index_resource) given the pb:latest-tagged-version relation exists in the index resource
26
28
 
27
29
  * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:latest-version_relation_exists_in_the_index_resource) given the pb:latest-version relation exists in the index resource
@@ -38,6 +40,8 @@
38
40
 
39
41
  * [A request to create a global webhook with a JSON body](#a_request_to_create_a_global_webhook_with_a_JSON_body)
40
42
 
43
+ * [A request to create a pacticipant](#a_request_to_create_a_pacticipant)
44
+
41
45
  * [A request to create a webhook for a consumer and provider](#a_request_to_create_a_webhook_for_a_consumer_and_provider_given_&#39;Condor&#39;_does_not_exist_in_the_pact-broker) given 'Condor' does not exist in the pact-broker
42
46
 
43
47
  * [A request to create a webhook with a JSON body and a uuid](#a_request_to_create_a_webhook_with_a_JSON_body_and_a_uuid_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
@@ -76,6 +80,10 @@
76
80
 
77
81
  * [A request to register the repository URL of a pacticipant](#a_request_to_register_the_repository_URL_of_a_pacticipant_given_the_&#39;Pricing_Service&#39;_does_not_exist_in_the_pact-broker) given the 'Pricing Service' does not exist in the pact-broker
78
82
 
83
+ * [A request to retrieve a pacticipant](#a_request_to_retrieve_a_pacticipant_given_a_pacticipant_with_name_Foo_exists) given a pacticipant with name Foo exists
84
+
85
+ * [A request to retrieve a pacticipant](#a_request_to_retrieve_a_pacticipant)
86
+
79
87
  * [A request to retrieve the latest 'production' version of Condor](#a_request_to_retrieve_the_latest_&#39;production&#39;_version_of_Condor_given_&#39;Condor&#39;_exists_in_the_pact-broker_with_the_latest_tagged_&#39;production&#39;_version_1.2.3) given 'Condor' exists in the pact-broker with the latest tagged 'production' version 1.2.3
80
88
 
81
89
  * [A request to retrieve the latest pact between Condor and the Pricing Service](#a_request_to_retrieve_the_latest_pact_between_Condor_and_the_Pricing_Service_given_a_pact_between_Condor_and_the_Pricing_Service_exists) given a pact between Condor and the Pricing Service exists
@@ -92,6 +100,8 @@
92
100
 
93
101
  * [A request to tag the production version of Condor](#a_request_to_tag_the_production_version_of_Condor_given_&#39;Condor&#39;_exists_in_the_pact-broker) given 'Condor' exists in the pact-broker
94
102
 
103
+ * [A request to update a pacticipant](#a_request_to_update_a_pacticipant_given_a_pacticipant_with_name_Foo_exists) given a pacticipant with name Foo exists
104
+
95
105
  * [A request to update a webhook](#a_request_to_update_a_webhook_given_a_webhook_with_the_uuid_696c5f93-1b7f-44bc-8d03-59440fcaa9a0_exists) given a webhook with the uuid 696c5f93-1b7f-44bc-8d03-59440fcaa9a0 exists
96
106
 
97
107
  * [An invalid request to create a webhook for a consumer and provider](#an_invalid_request_to_create_a_webhook_for_a_consumer_and_provider_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
@@ -506,6 +516,42 @@ Pact Broker will respond with:
506
516
  "_links": {
507
517
  "pb:webhooks": {
508
518
  "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-WEBHOOKS"
519
+ },
520
+ "pb:pacticipants": {
521
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANTS"
522
+ },
523
+ "pb:pacticipant": {
524
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-{pacticipant}"
525
+ }
526
+ }
527
+ }
528
+ }
529
+ ```
530
+ <a name="a_request_for_the_index_resource_given_the_pacticipant_relations_are_present"></a>
531
+ Given **the pacticipant relations are present**, upon receiving **a request for the index resource** from Pact Broker Client, with
532
+ ```json
533
+ {
534
+ "method": "get",
535
+ "path": "/",
536
+ "headers": {
537
+ "Accept": "application/hal+json"
538
+ }
539
+ }
540
+ ```
541
+ Pact Broker will respond with:
542
+ ```json
543
+ {
544
+ "status": 200,
545
+ "headers": {
546
+ "Content-Type": "application/hal+json;charset=utf-8"
547
+ },
548
+ "body": {
549
+ "_links": {
550
+ "pb:pacticipants": {
551
+ "href": "http://localhost:1234/pacticipants"
552
+ },
553
+ "pb:pacticipant": {
554
+ "href": "http://localhost:1234/pacticipants/{pacticipant}"
509
555
  }
510
556
  }
511
557
  }
@@ -778,6 +824,40 @@ Pact Broker will respond with:
778
824
  }
779
825
  }
780
826
  ```
827
+ <a name="a_request_to_create_a_pacticipant"></a>
828
+ Upon receiving **a request to create a pacticipant** from Pact Broker Client, with
829
+ ```json
830
+ {
831
+ "method": "post",
832
+ "path": "/pacticipants",
833
+ "headers": {
834
+ "Content-Type": "application/json",
835
+ "Accept": "application/hal+json"
836
+ },
837
+ "body": {
838
+ "name": "Foo",
839
+ "repositoryUrl": "http://foo"
840
+ }
841
+ }
842
+ ```
843
+ Pact Broker will respond with:
844
+ ```json
845
+ {
846
+ "status": 201,
847
+ "headers": {
848
+ "Content-Type": "application/hal+json;charset=utf-8"
849
+ },
850
+ "body": {
851
+ "name": "Foo",
852
+ "repositoryUrl": "http://foo",
853
+ "_links": {
854
+ "self": {
855
+ "href": "http://localhost:1234/pacticipants/Foo"
856
+ }
857
+ }
858
+ }
859
+ }
860
+ ```
781
861
  <a name="a_request_to_create_a_webhook_for_a_consumer_and_provider_given_&#39;Condor&#39;_does_not_exist_in_the_pact-broker"></a>
782
862
  Given **'Condor' does not exist in the pact-broker**, upon receiving **a request to create a webhook for a consumer and provider** from Pact Broker Client, with
783
863
  ```json
@@ -1598,6 +1678,50 @@ Pact Broker will respond with:
1598
1678
  }
1599
1679
  }
1600
1680
  ```
1681
+ <a name="a_request_to_retrieve_a_pacticipant_given_a_pacticipant_with_name_Foo_exists"></a>
1682
+ Given **a pacticipant with name Foo exists**, upon receiving **a request to retrieve a pacticipant** from Pact Broker Client, with
1683
+ ```json
1684
+ {
1685
+ "method": "get",
1686
+ "path": "/pacticipants/Foo",
1687
+ "headers": {
1688
+ "Accept": "application/hal+json"
1689
+ }
1690
+ }
1691
+ ```
1692
+ Pact Broker will respond with:
1693
+ ```json
1694
+ {
1695
+ "status": 200,
1696
+ "headers": {
1697
+ "Content-Type": "application/hal+json;charset=utf-8"
1698
+ },
1699
+ "body": {
1700
+ "_links": {
1701
+ "self": {
1702
+ "href": "http://localhost:1234/pacticipants/Foo"
1703
+ }
1704
+ }
1705
+ }
1706
+ }
1707
+ ```
1708
+ <a name="a_request_to_retrieve_a_pacticipant"></a>
1709
+ Upon receiving **a request to retrieve a pacticipant** from Pact Broker Client, with
1710
+ ```json
1711
+ {
1712
+ "method": "get",
1713
+ "path": "/pacticipants/Foo",
1714
+ "headers": {
1715
+ "Accept": "application/hal+json"
1716
+ }
1717
+ }
1718
+ ```
1719
+ Pact Broker will respond with:
1720
+ ```json
1721
+ {
1722
+ "status": 404
1723
+ }
1724
+ ```
1601
1725
  <a name="a_request_to_retrieve_the_latest_&#39;production&#39;_version_of_Condor_given_&#39;Condor&#39;_exists_in_the_pact-broker_with_the_latest_tagged_&#39;production&#39;_version_1.2.3"></a>
1602
1726
  Given **'Condor' exists in the pact-broker with the latest tagged 'production' version 1.2.3**, upon receiving **a request to retrieve the latest 'production' version of Condor** from Pact Broker Client, with
1603
1727
  ```json
@@ -1809,6 +1933,40 @@ Pact Broker will respond with:
1809
1933
  }
1810
1934
  }
1811
1935
  ```
1936
+ <a name="a_request_to_update_a_pacticipant_given_a_pacticipant_with_name_Foo_exists"></a>
1937
+ Given **a pacticipant with name Foo exists**, upon receiving **a request to update a pacticipant** from Pact Broker Client, with
1938
+ ```json
1939
+ {
1940
+ "method": "patch",
1941
+ "path": "/pacticipants/Foo",
1942
+ "headers": {
1943
+ "Content-Type": "application/json",
1944
+ "Accept": "application/hal+json"
1945
+ },
1946
+ "body": {
1947
+ "name": "Foo",
1948
+ "repositoryUrl": "http://foo"
1949
+ }
1950
+ }
1951
+ ```
1952
+ Pact Broker will respond with:
1953
+ ```json
1954
+ {
1955
+ "status": 200,
1956
+ "headers": {
1957
+ "Content-Type": "application/hal+json;charset=utf-8"
1958
+ },
1959
+ "body": {
1960
+ "name": "Foo",
1961
+ "repositoryUrl": "http://foo",
1962
+ "_links": {
1963
+ "self": {
1964
+ "href": "http://localhost:1234/pacticipants/Foo"
1965
+ }
1966
+ }
1967
+ }
1968
+ }
1969
+ ```
1812
1970
  <a name="a_request_to_update_a_webhook_given_a_webhook_with_the_uuid_696c5f93-1b7f-44bc-8d03-59440fcaa9a0_exists"></a>
1813
1971
  Given **a webhook with the uuid 696c5f93-1b7f-44bc-8d03-59440fcaa9a0 exists**, upon receiving **a request to update a webhook** from Pact Broker Client, with
1814
1972
  ```json
@@ -87,6 +87,8 @@ module PactBroker
87
87
  if retry_while_unknown?
88
88
  check_if_retry_while_unknown_supported(matrix)
89
89
  if matrix.any_unknown?
90
+ results = matrix.unknown_count == 1 ? "result" : "results"
91
+ $stderr.puts "Waiting for #{matrix.unknown_count} verification #{results} to be published (maximum of #{wait_time} seconds)"
90
92
  matrix = Retry.until_truthy_or_max_times(retry_options) do
91
93
  fetch_matrix
92
94
  end
@@ -120,6 +122,10 @@ module PactBroker
120
122
  options[:retry_while_unknown]
121
123
  end
122
124
 
125
+ def wait_time
126
+ retry_interval * retry_tries
127
+ end
128
+
123
129
  def check_if_retry_while_unknown_supported(matrix)
124
130
  if !matrix.supports_unknown_count?
125
131
  raise PactBroker::Client::Error.new("This version of the Pact Broker does not provide a count of the unknown verification results. Please upgrade your Broker to >= v2.23.4")
@@ -130,6 +130,15 @@ module PactBroker
130
130
  run_webhook_commands webhook_url
131
131
  end
132
132
 
133
+ desc 'test-webhook', 'Test the execution of a webhook'
134
+ method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
135
+ shared_authentication_options_for_pact_broker
136
+ def test_webhook
137
+ require 'pact_broker/client/webhooks/test'
138
+ result = PactBroker::Client::Webhooks::Test.call(options, pact_broker_client_options)
139
+ $stdout.puts result.message
140
+ end
141
+
133
142
  ignored_and_hidden_potential_options_from_environment_variables
134
143
  desc 'generate-uuid', 'Generate a UUID for use when calling create-or-update-webhook'
135
144
  def generate_uuid
@@ -138,6 +147,18 @@ module PactBroker
138
147
  puts SecureRandom.uuid
139
148
  end
140
149
 
150
+ desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
151
+ method_option :name, type: :string, required: true, desc: "Pacticipant name"
152
+ method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
153
+ shared_authentication_options_for_pact_broker
154
+ verbose_option
155
+ def create_or_update_pacticipant(*required_but_ignored)
156
+ raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
157
+ require 'pact_broker/client/pacticipants/create'
158
+ result = PactBroker::Client::Pacticipants2::Create.call({ name: options.name, repository_url: options.repository_url }, options.broker_base_url, pact_broker_client_options)
159
+ $stdout.puts result.message
160
+ end
161
+
141
162
  ignored_and_hidden_potential_options_from_environment_variables
142
163
  desc 'version', "Show the pact_broker-client gem version"
143
164
  def version
@@ -20,7 +20,7 @@ module PactBroker
20
20
  end
21
21
 
22
22
  def self.add_broker_config_from_environment_variables argv
23
- return argv if argv[0] == 'help'
23
+ return argv if argv[0] == 'help' || argv.empty?
24
24
 
25
25
  new_argv = add_option_from_environment_variable(argv, 'broker-base-url', 'b', 'PACT_BROKER_BASE_URL')
26
26
  new_argv = add_option_from_environment_variable(new_argv, 'broker-username', 'u', 'PACT_BROKER_USERNAME')
@@ -105,6 +105,17 @@ module PactBroker
105
105
  method_option :provider_verification_succeeded, type: :boolean, desc: "Trigger this webhook when a successful provider verification result is published"
106
106
  method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
107
107
  end
108
+
109
+ def self.shared_authentication_options_for_pact_broker
110
+ method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
111
+ method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
112
+ method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
113
+ method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
114
+ end
115
+
116
+ def self.verbose_option
117
+ method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
118
+ end
108
119
  end
109
120
  end
110
121
  end
@@ -29,6 +29,10 @@ module PactBroker
29
29
  _link(key).put(*args)
30
30
  end
31
31
 
32
+ def patch(key, *args)
33
+ _link(key).patch(*args)
34
+ end
35
+
32
36
  def can?(key)
33
37
  @links.key? key.to_s
34
38
  end
@@ -55,6 +59,10 @@ module PactBroker
55
59
  true
56
60
  end
57
61
 
62
+ def does_not_exist?
63
+ false
64
+ end
65
+
58
66
  def response
59
67
  @response
60
68
  end
@@ -83,7 +91,6 @@ module PactBroker
83
91
  end
84
92
 
85
93
  class ErrorEntity < Entity
86
-
87
94
  def initialize(href, data, http_client, response = nil)
88
95
  @href = href
89
96
  @data = data
@@ -92,6 +99,10 @@ module PactBroker
92
99
  @response = response
93
100
  end
94
101
 
102
+ def does_not_exist?
103
+ response && response.status == 404
104
+ end
105
+
95
106
  def success?
96
107
  false
97
108
  end
@@ -1,6 +1,7 @@
1
1
  require 'pact_broker/client/retry'
2
2
  require 'pact_broker/client/hal/authorization_header_redactor'
3
3
  require 'net/http'
4
+ require 'json'
4
5
 
5
6
  module PactBroker
6
7
  module Client
@@ -32,6 +33,11 @@ module PactBroker
32
33
  perform_request(create_request(uri, 'Post', body, headers), uri)
33
34
  end
34
35
 
36
+ def patch href, body = nil, headers = {}
37
+ uri = URI(href)
38
+ perform_request(create_request(uri, 'Patch', body, headers), uri)
39
+ end
40
+
35
41
  def create_request uri, http_method, body = nil, headers = {}
36
42
  request = Net::HTTP.const_get(http_method).new(uri.request_uri)
37
43
  request['Content-Type'] = "application/json" if ['Post', 'Put', 'Patch'].include?(http_method)
@@ -53,6 +53,10 @@ module PactBroker
53
53
  wrap_response(href, @http_client.post(href, payload ? JSON.dump(payload) : nil, headers))
54
54
  end
55
55
 
56
+ def patch(payload = nil, headers = {})
57
+ wrap_response(href, @http_client.patch(href, payload ? JSON.dump(payload) : nil, headers))
58
+ end
59
+
56
60
  def expand(params)
57
61
  expanded_url = expand_url(params, href)
58
62
  new_attrs = @attrs.merge('href' => expanded_url)
@@ -0,0 +1,15 @@
1
+ require 'pact_broker/client/hal'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module HalClientMethods
6
+ def create_index_entry_point(pact_broker_base_url, pact_broker_client_options)
7
+ PactBroker::Client::Hal::EntryPoint.new(pact_broker_base_url, create_http_client(pact_broker_client_options))
8
+ end
9
+
10
+ def create_http_client(pact_broker_client_options)
11
+ PactBroker::Client::Hal::HttpClient.new(pact_broker_client_options.merge(pact_broker_client_options[:basic_auth] || {}))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -11,7 +11,7 @@ module PactBroker
11
11
 
12
12
  def any_unknown?
13
13
  if supports_unknown_count?
14
- self[:summary][:unknown] > 0
14
+ unknown_count > 0
15
15
  else
16
16
  false
17
17
  end
@@ -21,6 +21,10 @@ module PactBroker
21
21
  !!(self[:summary] && Integer === self[:summary][:unknown] )
22
22
  end
23
23
 
24
+ def unknown_count
25
+ supports_unknown_count? ? self[:summary][:unknown] : nil
26
+ end
27
+
24
28
  def reason
25
29
  self[:summary][:reason]
26
30
  end
@@ -0,0 +1,57 @@
1
+ require 'pact_broker/client/hal'
2
+ require 'json'
3
+ require 'pact_broker/client/command_result'
4
+ require 'pact_broker/client/hal_client_methods'
5
+
6
+ module PactBroker
7
+ module Client
8
+ module Pacticipants2
9
+ class Create
10
+
11
+ include HalClientMethods
12
+
13
+ def self.call(params, pact_broker_base_url, pact_broker_client_options)
14
+ new(params, pact_broker_base_url, pact_broker_client_options).call
15
+ end
16
+
17
+ def initialize(params, pact_broker_base_url, pact_broker_client_options)
18
+ @params = params
19
+ @index_entry_point = create_index_entry_point(pact_broker_base_url, pact_broker_client_options)
20
+ @verbose = pact_broker_client_options[:verbose]
21
+ end
22
+
23
+ def call
24
+ pacticipant_entity = index_entity._link('pb:pacticipant').expand('pacticipant' => params[:name]).get
25
+ message = nil
26
+ response_entity = if pacticipant_entity.does_not_exist?
27
+ message = "Pacticipant \"#{params[:name]}\" created"
28
+ index_entity._link!('pb:pacticipants').post(pacticipant_resource_params)
29
+ else
30
+ message = "Pacticipant \"#{params[:name]}\" updated"
31
+ pacticipant_entity._link!('self').patch(pacticipant_resource_params)
32
+ end
33
+
34
+ response_entity.assert_success!
35
+ PactBroker::Client::CommandResult.new(true, message)
36
+ rescue StandardError => e
37
+ $stderr.puts("#{e.class} - #{e}\n#{e.backtrace.join("\n")}") if verbose
38
+ PactBroker::Client::CommandResult.new(false, "#{e.class} - #{e}")
39
+ end
40
+
41
+ private
42
+
43
+ attr_reader :index_entry_point, :params, :verbose
44
+
45
+ def index_entity
46
+ @index_entity ||= index_entry_point.get!
47
+ end
48
+
49
+ def pacticipant_resource_params
50
+ p = { name: params[:name] }
51
+ p[:repositoryUrl] = params[:repository_url] if params[:repository_url]
52
+ p
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -85,7 +85,7 @@ module PactBroker
85
85
  Retry.while_error do
86
86
  pacts = pact_broker_client.pacticipants.versions.pacts
87
87
  if pacts.version_published?(consumer: pact.consumer_name, provider: pact.provider_name, consumer_version: consumer_version)
88
- $stdout.puts ::Term::ANSIColor.yellow("The given version of pact is already published. Overwriting...")
88
+ $stdout.puts ::Term::ANSIColor.yellow("A pact for this consumer version is already published. Overwriting. (Note: Overwriting pacts is not recommended as it can lead to race conditions. Best practice is to provide a unique consumer version number for each publication.)")
89
89
  end
90
90
 
91
91
  latest_pact_url = pacts.publish(pact_hash: pact, consumer_version: consumer_version)
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.25.1'
3
+ VERSION = '1.26.0'
4
4
  end
5
5
  end
@@ -0,0 +1,17 @@
1
+
2
+ require 'pact_broker/client/hal'
3
+ require 'pact_broker/client/command_result'
4
+
5
+ module PactBroker
6
+ module Client
7
+ module Webhooks
8
+ class Test
9
+ def self.call(options, pact_broker_client_options)
10
+ http_client = PactBroker::Client::Hal::HttpClient.new(pact_broker_client_options.merge(pact_broker_client_options[:basic_auth] || {}))
11
+ execution_result = PactBroker::Client::Hal::EntryPoint.new(options.broker_base_url, http_client).get!._link!('pb:webhook').expand('uuid' => options.uuid).get!.post('pb:execute')
12
+ PactBroker::Client::CommandResult.new(true, execution_result.response.body['logs'])
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,7 +1,7 @@
1
- describe "pact-broker can-i-deploy", skip_windows: true, skip_ci: true do
1
+ describe "pact-broker can-i-deploy", skip_windows: true do
2
2
  before(:all) do
3
- @pipe = IO.popen("bundle exec pact-stub-service spec/pacts/pact_broker_client-pact_broker.json -p 5000")
4
- sleep 2
3
+ @pipe = IO.popen("bundle exec pact-stub-service spec/pacts/pact_broker_client-pact_broker.json -p 5000 --log tmp/pact-stub-can-i-deploy.log")
4
+ sleep 4
5
5
  end
6
6
 
7
7
  context "when the pacticipants can be deployed" do
@@ -1,7 +1,6 @@
1
- # Currently failing on Travis, skip for now
2
- describe "pact-broker create-version-tag", skip_windows: true, skip_ci: true do
1
+ describe "pact-broker create-version-tag", skip_windows: true do
3
2
  before(:all) do
4
- @pipe = IO.popen("bundle exec pact-stub-service spec/pacts/pact_broker_client-pact_broker.json -p 5001")
3
+ @pipe = IO.popen("bundle exec pact-stub-service spec/pacts/pact_broker_client-pact_broker.json -p 5001 --log tmp/pact-stub-service-create-verison-tag.log")
5
4
  sleep 2
6
5
  end
7
6
 
@@ -9,11 +9,19 @@ module PactBroker
9
9
  let(:matrix_options) { {} }
10
10
  let(:pact_broker_client_options) { { foo: 'bar' } }
11
11
  let(:matrix_client) { instance_double('PactBroker::Client::Matrix') }
12
- let(:matrix) { instance_double('Matrix::Resource', deployable?: true, reason: 'some reason', any_unknown?: any_unknown, supports_unknown_count?: supports_unknown_count) }
13
- let(:any_unknown) { false }
12
+ let(:matrix) do
13
+ instance_double('Matrix::Resource',
14
+ deployable?: true,
15
+ reason: 'some reason',
16
+ any_unknown?: any_unknown,
17
+ supports_unknown_count?: supports_unknown_count,
18
+ unknown_count: unknown_count)
19
+ end
20
+ let(:unknown_count) { 0 }
21
+ let(:any_unknown) { unknown_count > 0 }
14
22
  let(:supports_unknown_count) { true }
15
23
  let(:retry_while_unknown) { 0 }
16
- let(:options) { { output: 'text', retry_while_unknown: retry_while_unknown, retry_interval: 5} }
24
+ let(:options) { { output: 'text', retry_while_unknown: retry_while_unknown, retry_interval: 5 } }
17
25
 
18
26
 
19
27
  before do
@@ -76,7 +84,17 @@ module PactBroker
76
84
  end
77
85
 
78
86
  context "when any_unknown? is true" do
79
- let(:any_unknown) { true }
87
+ before do
88
+ allow($stderr).to receive(:puts)
89
+ allow(Retry).to receive(:until_truthy_or_max_times)
90
+ end
91
+
92
+ let(:unknown_count) { 1 }
93
+
94
+ it "puts a message to stderr" do
95
+ expect($stderr).to receive(:puts).with("Waiting for 1 verification result to be published (maximum of 5 seconds)")
96
+ subject
97
+ end
80
98
 
81
99
  it "retries the request" do
82
100
  expect(Retry).to receive(:until_truthy_or_max_times).with(hash_including(times: 1, sleep: 5, sleep_first: true))
@@ -0,0 +1,28 @@
1
+ require 'pact_broker/client/pacticipants/create'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Pacticipants2
6
+ describe Create do
7
+ describe ".call" do
8
+ let(:pact_broker_client_options) { {} }
9
+ let(:broker_base_url) { "http://url" }
10
+ let(:params) { { name: 'Foo' } }
11
+
12
+ subject { Create.call(params, broker_base_url, pact_broker_client_options)}
13
+
14
+ context "when there is an http error" do
15
+ let!(:index_request) do
16
+ stub_request(:get, broker_base_url).to_return(status: 500, body: 'some error', headers: { "Content-Type" => "application/hal+json" } )
17
+ end
18
+
19
+ it "returns a failure result" do
20
+ expect(subject.success).to be false
21
+ expect(subject.message).to include 'some error'
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1249,6 +1249,161 @@
1249
1249
  }
1250
1250
  }
1251
1251
  },
1252
+ {
1253
+ "description": "a request for the index resource",
1254
+ "providerState": "the pacticipant relations are present",
1255
+ "request": {
1256
+ "method": "get",
1257
+ "path": "/",
1258
+ "headers": {
1259
+ "Accept": "application/hal+json"
1260
+ }
1261
+ },
1262
+ "response": {
1263
+ "status": 200,
1264
+ "headers": {
1265
+ "Content-Type": "application/hal+json;charset=utf-8"
1266
+ },
1267
+ "body": {
1268
+ "_links": {
1269
+ "pb:pacticipants": {
1270
+ "href": "http://localhost:1234/pacticipants"
1271
+ },
1272
+ "pb:pacticipant": {
1273
+ "href": "http://localhost:1234/pacticipants/{pacticipant}"
1274
+ }
1275
+ }
1276
+ },
1277
+ "matchingRules": {
1278
+ "$.body._links.pb:pacticipants.href": {
1279
+ "match": "regex",
1280
+ "regex": "http:\\/\\/.*"
1281
+ },
1282
+ "$.body._links.pb:pacticipant.href": {
1283
+ "match": "regex",
1284
+ "regex": "http:\\/\\/.*\\{pacticipant\\}"
1285
+ }
1286
+ }
1287
+ }
1288
+ },
1289
+ {
1290
+ "description": "a request to retrieve a pacticipant",
1291
+ "request": {
1292
+ "method": "get",
1293
+ "path": "/pacticipants/Foo",
1294
+ "headers": {
1295
+ "Accept": "application/hal+json"
1296
+ }
1297
+ },
1298
+ "response": {
1299
+ "status": 404,
1300
+ "headers": {
1301
+ }
1302
+ }
1303
+ },
1304
+ {
1305
+ "description": "a request to create a pacticipant",
1306
+ "request": {
1307
+ "method": "post",
1308
+ "path": "/pacticipants",
1309
+ "headers": {
1310
+ "Content-Type": "application/json",
1311
+ "Accept": "application/hal+json"
1312
+ },
1313
+ "body": {
1314
+ "name": "Foo",
1315
+ "repositoryUrl": "http://foo"
1316
+ }
1317
+ },
1318
+ "response": {
1319
+ "status": 201,
1320
+ "headers": {
1321
+ "Content-Type": "application/hal+json;charset=utf-8"
1322
+ },
1323
+ "body": {
1324
+ "name": "Foo",
1325
+ "repositoryUrl": "http://foo",
1326
+ "_links": {
1327
+ "self": {
1328
+ "href": "http://localhost:1234/pacticipants/Foo"
1329
+ }
1330
+ }
1331
+ },
1332
+ "matchingRules": {
1333
+ "$.body._links.self.href": {
1334
+ "match": "regex",
1335
+ "regex": "http:\\/\\/.*"
1336
+ }
1337
+ }
1338
+ }
1339
+ },
1340
+ {
1341
+ "description": "a request to retrieve a pacticipant",
1342
+ "providerState": "a pacticipant with name Foo exists",
1343
+ "request": {
1344
+ "method": "get",
1345
+ "path": "/pacticipants/Foo",
1346
+ "headers": {
1347
+ "Accept": "application/hal+json"
1348
+ }
1349
+ },
1350
+ "response": {
1351
+ "status": 200,
1352
+ "headers": {
1353
+ "Content-Type": "application/hal+json;charset=utf-8"
1354
+ },
1355
+ "body": {
1356
+ "_links": {
1357
+ "self": {
1358
+ "href": "http://localhost:1234/pacticipants/Foo"
1359
+ }
1360
+ }
1361
+ },
1362
+ "matchingRules": {
1363
+ "$.body._links.self.href": {
1364
+ "match": "regex",
1365
+ "regex": "http:\\/\\/.*"
1366
+ }
1367
+ }
1368
+ }
1369
+ },
1370
+ {
1371
+ "description": "a request to update a pacticipant",
1372
+ "providerState": "a pacticipant with name Foo exists",
1373
+ "request": {
1374
+ "method": "patch",
1375
+ "path": "/pacticipants/Foo",
1376
+ "headers": {
1377
+ "Content-Type": "application/json",
1378
+ "Accept": "application/hal+json"
1379
+ },
1380
+ "body": {
1381
+ "name": "Foo",
1382
+ "repositoryUrl": "http://foo"
1383
+ }
1384
+ },
1385
+ "response": {
1386
+ "status": 200,
1387
+ "headers": {
1388
+ "Content-Type": "application/hal+json;charset=utf-8"
1389
+ },
1390
+ "body": {
1391
+ "name": "Foo",
1392
+ "repositoryUrl": "http://foo",
1393
+ "_links": {
1394
+ "self": {
1395
+ "href": "http://localhost:1234/pacticipants/Foo"
1396
+ }
1397
+ }
1398
+ },
1399
+ "matchingRules": {
1400
+ "$.body._links.self.href": {
1401
+ "match": "regex",
1402
+ "regex": "http:\\/\\/.*"
1403
+ }
1404
+ }
1405
+ }
1406
+ },
1252
1407
  {
1253
1408
  "description": "a request to create a webhook with a JSON body for a consumer and provider",
1254
1409
  "providerState": "the 'Pricing Service' and 'Condor' already exist in the pact-broker",
@@ -1550,6 +1705,12 @@
1550
1705
  "_links": {
1551
1706
  "pb:webhooks": {
1552
1707
  "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-WEBHOOKS"
1708
+ },
1709
+ "pb:pacticipants": {
1710
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANTS"
1711
+ },
1712
+ "pb:pacticipant": {
1713
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-{pacticipant}"
1553
1714
  }
1554
1715
  }
1555
1716
  },
@@ -1557,6 +1718,14 @@
1557
1718
  "$.body._links.pb:webhooks.href": {
1558
1719
  "match": "regex",
1559
1720
  "regex": "http:\\/\\/.*"
1721
+ },
1722
+ "$.body._links.pb:pacticipants.href": {
1723
+ "match": "regex",
1724
+ "regex": "http:\\/\\/.*"
1725
+ },
1726
+ "$.body._links.pb:pacticipant.href": {
1727
+ "match": "regex",
1728
+ "regex": "http:\\/\\/.*{pacticipant}"
1560
1729
  }
1561
1730
  }
1562
1731
  }
@@ -58,12 +58,41 @@ module PactBrokerPactHelperMethods
58
58
  _links: {
59
59
  :'pb:webhooks' => {
60
60
  href: placeholder_url_term('pb:webhooks')
61
+ },
62
+ :'pb:pacticipants' => {
63
+ href: placeholder_url_term('pb:pacticipants')
64
+ },
65
+ :'pb:pacticipant' => {
66
+ href: placeholder_url_term('pb:pacticipant', ['pacticipant'])
61
67
  }
62
68
  }
63
69
  }
64
70
  )
65
71
  end
66
72
 
73
+ def mock_pact_broker_index_with_relations(context, links, provider_state)
74
+ _links = links.each_with_object({}) do | (key, value), new_links |
75
+ new_links[key] = {
76
+ href: value
77
+ }
78
+ end
79
+
80
+ pact_broker
81
+ .given(provider_state)
82
+ .upon_receiving("a request for the index resource")
83
+ .with(
84
+ method: :get,
85
+ path: '/',
86
+ headers: context.get_request_headers).
87
+ will_respond_with(
88
+ status: 200,
89
+ headers: context.pact_broker_response_headers,
90
+ body: {
91
+ _links: _links
92
+ }
93
+ )
94
+ end
95
+
67
96
  def mock_pact_broker_index_with_webhook_relation(context)
68
97
  pact_broker
69
98
  .upon_receiving("a request for the index resource with the webhook relation")
@@ -0,0 +1,118 @@
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) { {} }
58
+
59
+ subject { PactBroker::Client::Pacticipants2::Create.call(params, broker_base_url, pact_broker_client_options) }
60
+
61
+ context "when the pacticipant does not already exist" do
62
+ before do
63
+ pact_broker
64
+ .upon_receiving("a request to retrieve a pacticipant")
65
+ .with(
66
+ method: :get,
67
+ path: '/pacticipants/Foo',
68
+ headers: get_request_headers)
69
+ .will_respond_with(status: 404)
70
+
71
+ pact_broker
72
+ .upon_receiving("a request to create a pacticipant")
73
+ .with(
74
+ method: :post,
75
+ path: '/pacticipants',
76
+ headers: post_request_headers,
77
+ body: request_body)
78
+ .will_respond_with(create_success_response)
79
+ end
80
+
81
+ it "returns a CommandResult with success = true" do
82
+ expect(subject).to be_a PactBroker::Client::CommandResult
83
+ expect(subject.success).to be true
84
+ expect(subject.message).to eq "Pacticipant \"Foo\" created"
85
+ end
86
+ end
87
+
88
+ context "when the pacticipant does already exist" do
89
+ before do
90
+ pact_broker
91
+ .given("a pacticipant with name Foo exists")
92
+ .upon_receiving("a request to retrieve a pacticipant")
93
+ .with(
94
+ method: :get,
95
+ path: '/pacticipants/Foo',
96
+ headers: get_request_headers)
97
+ .will_respond_with(get_success_response)
98
+
99
+ pact_broker
100
+ .given("a pacticipant with name Foo exists")
101
+ .upon_receiving("a request to update a pacticipant")
102
+ .with(
103
+ method: :patch,
104
+ path: '/pacticipants/Foo',
105
+ headers: post_request_headers,
106
+ body: request_body)
107
+ .will_respond_with(create_success_response)
108
+ end
109
+
110
+ let(:response_status) { 200 }
111
+
112
+ it "returns a CommandResult with success = true" do
113
+ expect(subject).to be_a PactBroker::Client::CommandResult
114
+ expect(subject.success).to be true
115
+ expect(subject.message).to eq "Pacticipant \"Foo\" updated"
116
+ end
117
+ end
118
+ 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.25.1
4
+ version: 1.26.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: 2020-04-02 00:00:00.000000000 Z
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -213,6 +213,7 @@ files:
213
213
  - lib/pact_broker/client/hal/entry_point.rb
214
214
  - lib/pact_broker/client/hal/http_client.rb
215
215
  - lib/pact_broker/client/hal/link.rb
216
+ - lib/pact_broker/client/hal_client_methods.rb
216
217
  - lib/pact_broker/client/matrix.rb
217
218
  - lib/pact_broker/client/matrix/formatter.rb
218
219
  - lib/pact_broker/client/matrix/json_formatter.rb
@@ -223,6 +224,7 @@ files:
223
224
  - lib/pact_broker/client/pact_file.rb
224
225
  - lib/pact_broker/client/pact_hash.rb
225
226
  - lib/pact_broker/client/pacticipants.rb
227
+ - lib/pact_broker/client/pacticipants/create.rb
226
228
  - lib/pact_broker/client/pacts.rb
227
229
  - lib/pact_broker/client/publish_pacts.rb
228
230
  - lib/pact_broker/client/retry.rb
@@ -235,6 +237,7 @@ files:
235
237
  - lib/pact_broker/client/versions/json_formatter.rb
236
238
  - lib/pact_broker/client/versions/text_formatter.rb
237
239
  - lib/pact_broker/client/webhooks/create.rb
240
+ - lib/pact_broker/client/webhooks/test.rb
238
241
  - lib/pact_broker_client.rb
239
242
  - pact-broker-client.gemspec
240
243
  - script/generate-cli-usage.sh
@@ -261,6 +264,7 @@ files:
261
264
  - spec/lib/pact_broker/client/matrix_spec.rb
262
265
  - spec/lib/pact_broker/client/merge_pacts_spec.rb
263
266
  - spec/lib/pact_broker/client/pact_broker_client_spec.rb
267
+ - spec/lib/pact_broker/client/pacticipants/create_spec.rb
264
268
  - spec/lib/pact_broker/client/pacticipants_spec.rb
265
269
  - spec/lib/pact_broker/client/publish_pacts_spec.rb
266
270
  - spec/lib/pact_broker/client/retry_spec.rb
@@ -279,6 +283,7 @@ files:
279
283
  - spec/service_providers/pact_broker_client_tags_spec.rb
280
284
  - spec/service_providers/pact_broker_client_versions_spec.rb
281
285
  - spec/service_providers/pact_helper.rb
286
+ - spec/service_providers/pacticipants_create_spec.rb
282
287
  - spec/service_providers/webhooks_create_spec.rb
283
288
  - spec/spec_helper.rb
284
289
  - spec/support/cli_test_pacts/bar.json
@@ -311,8 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
316
  - !ruby/object:Gem::Version
312
317
  version: '0'
313
318
  requirements: []
314
- rubyforge_project:
315
- rubygems_version: 2.7.6
319
+ rubygems_version: 3.1.2
316
320
  signing_key:
317
321
  specification_version: 4
318
322
  summary: See description
@@ -338,6 +342,7 @@ test_files:
338
342
  - spec/lib/pact_broker/client/matrix_spec.rb
339
343
  - spec/lib/pact_broker/client/merge_pacts_spec.rb
340
344
  - spec/lib/pact_broker/client/pact_broker_client_spec.rb
345
+ - spec/lib/pact_broker/client/pacticipants/create_spec.rb
341
346
  - spec/lib/pact_broker/client/pacticipants_spec.rb
342
347
  - spec/lib/pact_broker/client/publish_pacts_spec.rb
343
348
  - spec/lib/pact_broker/client/retry_spec.rb
@@ -356,6 +361,7 @@ test_files:
356
361
  - spec/service_providers/pact_broker_client_tags_spec.rb
357
362
  - spec/service_providers/pact_broker_client_versions_spec.rb
358
363
  - spec/service_providers/pact_helper.rb
364
+ - spec/service_providers/pacticipants_create_spec.rb
359
365
  - spec/service_providers/webhooks_create_spec.rb
360
366
  - spec/spec_helper.rb
361
367
  - spec/support/cli_test_pacts/bar.json