pact_broker 2.4.2 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +4 -2
- data/CHANGELOG.md +54 -0
- data/DEVELOPER_DOCUMENTATION.md +11 -7
- data/README.md +5 -1
- data/UPGRADING.md +18 -0
- data/db/migrations/19_make_pact_version_content_sha_not_nullable.rb +9 -1
- data/db/migrations/25_make_pv_pacticipants_mandatory.rb +8 -0
- data/db/migrations/38_create_triggered_webhooks_table.rb +19 -0
- data/db/migrations/39_add_triggered_webhooks_fk_to_execution.rb +24 -0
- data/db/migrations/40_create_latest_triggered_webhooks_view.rb +24 -0
- data/db/migrations/41_migrate_execution_data.rb +47 -0
- data/db/test/backwards_compatibility/.rspec +3 -0
- data/db/test/backwards_compatibility/Appraisals +49 -0
- data/db/test/backwards_compatibility/Gemfile +11 -0
- data/db/test/backwards_compatibility/Rakefile +55 -0
- data/db/test/backwards_compatibility/config.ru +18 -0
- data/db/test/backwards_compatibility/gemfiles/1.18.0.gemfile +14 -0
- data/db/test/backwards_compatibility/gemfiles/1.18.0.gemfile.lock +210 -0
- data/db/test/backwards_compatibility/gemfiles/2.0.0.gemfile +14 -0
- data/db/test/backwards_compatibility/gemfiles/2.0.0.gemfile.lock +208 -0
- data/db/test/backwards_compatibility/gemfiles/2.1.0.gemfile +14 -0
- data/db/test/backwards_compatibility/gemfiles/2.1.0.gemfile.lock +209 -0
- data/db/test/backwards_compatibility/gemfiles/2.2.0.gemfile +14 -0
- data/db/test/backwards_compatibility/gemfiles/2.2.0.gemfile.lock +197 -0
- data/db/test/backwards_compatibility/gemfiles/2.3.0.gemfile +13 -0
- data/db/test/backwards_compatibility/gemfiles/2.3.0.gemfile.lock +196 -0
- data/db/test/backwards_compatibility/gemfiles/2.4.2.gemfile +13 -0
- data/db/test/backwards_compatibility/gemfiles/2.4.2.gemfile.lock +196 -0
- data/db/test/backwards_compatibility/gemfiles/head.gemfile +13 -0
- data/db/test/backwards_compatibility/gemfiles/head.gemfile.lock +200 -0
- data/db/test/backwards_compatibility/spec/fixtures/foo-bar.json +22 -0
- data/db/test/backwards_compatibility/spec/publish_pact_spec.rb +72 -0
- data/db/test/backwards_compatibility/spec/spec_helper.rb +20 -0
- data/db/test/backwards_compatibility/spec/support/fixture_helpers.rb +12 -0
- data/db/test/backwards_compatibility/spec/support/request_helpers.rb +20 -0
- data/example/Gemfile +2 -2
- data/example/pact_broker_database.sqlite3 +0 -0
- data/lib/pact_broker/api/decorators/pact_collection_decorator.rb +1 -2
- data/lib/pact_broker/api/decorators/pact_decorator.rb +12 -10
- data/lib/pact_broker/api/decorators/pact_versions_decorator.rb +1 -2
- data/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb +123 -0
- data/lib/pact_broker/api/decorators/versions_decorator.rb +17 -6
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +8 -10
- data/lib/pact_broker/api/decorators/webhooks_decorator.rb +0 -1
- data/lib/pact_broker/api/pact_broker_urls.rb +13 -1
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +47 -3
- data/lib/pact_broker/api/resources/badge.rb +3 -3
- data/lib/pact_broker/api/resources/base_resource.rb +1 -1
- data/lib/pact_broker/api/resources/latest_pact.rb +5 -1
- data/lib/pact_broker/api/resources/pact.rb +5 -1
- data/lib/pact_broker/api/resources/pact_webhooks_status.rb +61 -0
- data/lib/pact_broker/api/resources/triggered_webhook_logs.rb +36 -0
- data/lib/pact_broker/api/resources/webhook.rb +31 -3
- data/lib/pact_broker/api/resources/webhook_execution.rb +12 -2
- data/lib/pact_broker/api.rb +3 -0
- data/lib/pact_broker/app.rb +11 -3
- data/lib/pact_broker/badges/service.rb +26 -5
- data/lib/pact_broker/configuration.rb +12 -5
- data/lib/pact_broker/constants.rb +1 -1
- data/lib/pact_broker/diagnostic/resources/heartbeat.rb +1 -2
- data/lib/pact_broker/doc/views/pact-webhooks.markdown +1 -1
- data/lib/pact_broker/doc/views/webhooks-webhooks.markdown +1 -1
- data/lib/pact_broker/doc/views/webhooks.markdown +1 -1
- data/lib/pact_broker/domain/relationship.rb +13 -4
- data/lib/pact_broker/domain/verification.rb +0 -4
- data/lib/pact_broker/domain/webhook.rb +2 -6
- data/lib/pact_broker/domain/webhook_execution_result.rb +1 -2
- data/lib/pact_broker/domain/webhook_request.rb +59 -40
- data/lib/pact_broker/pacticipants/service.rb +4 -3
- data/lib/pact_broker/pacts/repository.rb +8 -0
- data/lib/pact_broker/pacts/service.rb +2 -0
- data/lib/pact_broker/services.rb +1 -1
- data/lib/pact_broker/ui/view_models/relationship.rb +29 -2
- data/lib/pact_broker/ui/views/relationships/show.haml +7 -10
- data/lib/pact_broker/verifications/repository.rb +8 -1
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/webhooks/execution.rb +25 -4
- data/lib/pact_broker/webhooks/job.rb +55 -13
- data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +9 -0
- data/lib/pact_broker/webhooks/redact_logs.rb +10 -0
- data/lib/pact_broker/webhooks/repository.rb +76 -8
- data/lib/pact_broker/webhooks/service.rb +48 -8
- data/lib/pact_broker/webhooks/status.rb +29 -0
- data/lib/pact_broker/webhooks/triggered_webhook.rb +96 -0
- data/lib/pact_broker/webhooks/webhook.rb +19 -8
- data/lib/rack/pact_broker/database_transaction.rb +9 -3
- data/pact_broker.gemspec +3 -3
- data/public/javascripts/pact.js +5 -0
- data/public/stylesheets/pact.css +14 -1
- data/public/stylesheets/relationships.css +0 -1
- data/script/db-spec.sh +7 -0
- data/script/seed.rb +13 -8
- data/spec/features/create_webhook_spec.rb +1 -1
- data/spec/features/delete_pact_spec.rb +5 -1
- data/spec/features/delete_webhook_spec.rb +2 -1
- data/spec/features/edit_webhook_spec.rb +61 -0
- data/spec/features/execute_webhook_spec.rb +73 -0
- data/spec/features/get_latest_pact_badge_spec.rb +1 -1
- data/spec/features/get_latest_tagged_pact_badge_spec.rb +1 -1
- data/spec/features/get_latest_untagged_pact_badge_spec.rb +1 -1
- data/spec/features/get_pact_spec.rb +1 -1
- data/spec/features/merge_pact_spec.rb +1 -1
- data/spec/features/publish_pact_spec.rb +1 -1
- data/spec/integration/app_spec.rb +1 -1
- data/spec/integration/endpoints/group.rb +1 -1
- data/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +2 -1
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +8 -6
- data/spec/lib/pact_broker/api/decorators/pact_webhooks_status_decorator_spec.rb +134 -0
- data/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb +1 -1
- data/spec/lib/pact_broker/api/decorators/representable_pact_spec.rb +1 -1
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +27 -1
- data/spec/lib/pact_broker/api/resources/badge_spec.rb +32 -15
- data/spec/lib/pact_broker/api/resources/base_resource_spec.rb +17 -0
- data/spec/lib/pact_broker/api/resources/latest_pact_spec.rb +5 -3
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +9 -2
- data/spec/lib/pact_broker/api/resources/triggered_webhook_logs_spec.rb +28 -0
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +15 -5
- data/spec/lib/pact_broker/api/resources/webhook_spec.rb +43 -31
- data/spec/lib/pact_broker/app_spec.rb +12 -8
- data/spec/lib/pact_broker/badges/service_spec.rb +15 -1
- data/spec/lib/pact_broker/configuration_spec.rb +3 -2
- data/spec/lib/pact_broker/domain/relationship_spec.rb +24 -0
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +47 -31
- data/spec/lib/pact_broker/domain/webhook_spec.rb +4 -6
- data/spec/lib/pact_broker/pacticipants/service_spec.rb +16 -1
- data/spec/lib/pact_broker/pacts/repository_spec.rb +22 -1
- data/spec/lib/pact_broker/pacts/service_spec.rb +32 -1
- data/spec/lib/pact_broker/ui/view_models/relationship_spec.rb +44 -0
- data/spec/lib/pact_broker/verifications/repository_spec.rb +19 -0
- data/spec/lib/pact_broker/verifications/service_spec.rb +1 -1
- data/spec/lib/pact_broker/webhooks/job_spec.rb +80 -19
- data/spec/lib/pact_broker/webhooks/redact_logs_spec.rb +49 -0
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +271 -21
- data/spec/lib/pact_broker/webhooks/service_spec.rb +70 -3
- data/spec/lib/pact_broker/webhooks/status_spec.rb +48 -0
- data/spec/lib/pact_broker/webhooks/triggered_webhook_spec.rb +40 -0
- data/spec/lib/rack/pact_broker/database_transaction_spec.rb +14 -4
- data/spec/migrations/23_pact_versions_spec.rb +8 -30
- data/spec/migrations/24_populate_pact_contents_spec.rb +3 -21
- data/spec/migrations/34_latest_tagged_pacts_spec.rb +1 -17
- data/spec/migrations/34_pact_revisions_spec.rb +7 -23
- data/spec/migrations/41_migrate_execution_data_spec.rb +109 -0
- data/spec/service_consumers/pact_helper.rb +5 -1
- data/spec/spec_helper.rb +15 -7
- data/spec/support/database_cleaner.rb +15 -2
- data/spec/support/migration_helpers.rb +16 -0
- data/spec/support/test_data_builder.rb +41 -9
- data/tasks/database.rb +7 -2
- data/tasks/db.rake +10 -0
- data/tasks/rspec.rake +1 -1
- data/vendor/hal-browser/browser.html +3 -2
- data/vendor/hal-browser/js/hal/resource.js +16 -2
- metadata +72 -13
- data/script/record_verification.sh +0 -4
@@ -20,12 +20,22 @@ module PactBroker
|
|
20
20
|
stub_request(:get, expected_url).to_return(:status => response_status, :body => "svg")
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
subject { PactBroker::Badges::Service.pact_verification_badge pact, label, initials, verification_status }
|
24
|
+
|
25
|
+
before do
|
26
|
+
Service.clear_cache
|
27
|
+
end
|
24
28
|
|
25
29
|
it "returns the svg file" do
|
26
30
|
expect(subject).to eq "svg"
|
27
31
|
end
|
28
32
|
|
33
|
+
it "caches the response" do
|
34
|
+
PactBroker::Badges::Service.pact_verification_badge pact, label, initials, verification_status
|
35
|
+
PactBroker::Badges::Service.pact_verification_badge pact, label, initials, verification_status
|
36
|
+
expect(http_request).to have_been_made.once
|
37
|
+
end
|
38
|
+
|
29
39
|
context "when the label is not specified" do
|
30
40
|
it "creates a badge with the consumer and provider names" do
|
31
41
|
subject
|
@@ -221,6 +231,10 @@ module PactBroker
|
|
221
231
|
it "returns a static image" do
|
222
232
|
expect(subject).to include ">pact</"
|
223
233
|
end
|
234
|
+
|
235
|
+
it "does not cache the response" do
|
236
|
+
expect(Service::CACHE.size).to eq 0
|
237
|
+
end
|
224
238
|
end
|
225
239
|
|
226
240
|
context "when the shields_io_base_url is not configured" do
|
@@ -10,10 +10,11 @@ module PactBroker
|
|
10
10
|
describe ".html_pact_renderer" do
|
11
11
|
|
12
12
|
let(:pact) { double('pact') }
|
13
|
+
let(:options) { double('options') }
|
13
14
|
|
14
15
|
it "calls the inbuilt HtmlPactRenderer" do
|
15
|
-
expect(PactBroker::Api::Renderers::HtmlPactRenderer).to receive(:call).with(pact)
|
16
|
-
PactBroker.configuration.html_pact_renderer.call pact
|
16
|
+
expect(PactBroker::Api::Renderers::HtmlPactRenderer).to receive(:call).with(pact, options)
|
17
|
+
PactBroker.configuration.html_pact_renderer.call pact, options
|
17
18
|
end
|
18
19
|
|
19
20
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'pact_broker/domain/relationship'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Domain
|
5
|
+
describe Relationship do
|
6
|
+
describe "#last_webhook_execution_date" do
|
7
|
+
let(:webhook_execution_1) { double('webhook_execution', created_at: DateTime.new(2013)) }
|
8
|
+
let(:webhook_execution_2) { double('webhook_execution', created_at: DateTime.new(2015)) }
|
9
|
+
|
10
|
+
let(:webhook_executions) { [webhook_execution_1, webhook_execution_2] }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(webhook_executions).to receive(:sort).and_return(webhook_executions)
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { Relationship.create(nil, nil, nil, nil, [], webhook_executions) }
|
17
|
+
|
18
|
+
it "returns the created_at date of the last execution" do
|
19
|
+
expect(subject.last_webhook_execution_date).to eq DateTime.new(2015)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -14,17 +14,20 @@ module PactBroker
|
|
14
14
|
let(:body) { 'body' }
|
15
15
|
let(:logs) { StringIO.new }
|
16
16
|
let(:execution_logger) { Logger.new(logs) }
|
17
|
+
let(:options) { {failure_log_message: 'oops'}}
|
17
18
|
|
18
19
|
subject do
|
19
20
|
WebhookRequest.new(
|
20
21
|
method: 'post',
|
21
22
|
url: url,
|
22
|
-
headers: {'Content-Type' => 'text/plain'},
|
23
|
+
headers: {'Content-Type' => 'text/plain', 'Authorization' => 'foo'},
|
23
24
|
username: username,
|
24
25
|
password: password,
|
25
26
|
body: body)
|
26
27
|
end
|
27
28
|
|
29
|
+
let(:logs) { subject.execute(options).logs }
|
30
|
+
|
28
31
|
describe "description" do
|
29
32
|
it "returns a brief description of the HTTP request" do
|
30
33
|
expect(subject.description).to eq 'POST example.org'
|
@@ -50,34 +53,29 @@ module PactBroker
|
|
50
53
|
let!(:http_request) do
|
51
54
|
stub_request(:post, "http://example.org/hook").
|
52
55
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body').
|
53
|
-
to_return(:status =>
|
56
|
+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
54
57
|
end
|
55
58
|
|
56
59
|
it "executes the configured request" do
|
57
|
-
subject.execute
|
60
|
+
subject.execute(options)
|
58
61
|
expect(http_request).to have_been_made
|
59
62
|
end
|
60
63
|
|
61
64
|
it "logs the request" do
|
62
65
|
allow(PactBroker.logger).to receive(:info)
|
63
66
|
expect(PactBroker.logger).to receive(:info).with(/POST.*example.*text.*body/)
|
64
|
-
subject.execute
|
67
|
+
subject.execute(options)
|
65
68
|
end
|
66
69
|
|
67
70
|
it "logs the response" do
|
68
71
|
allow(PactBroker.logger).to receive(:info)
|
69
72
|
allow(PactBroker.logger).to receive(:debug)
|
70
|
-
expect(PactBroker.logger).to receive(:info).with(/response.*
|
73
|
+
expect(PactBroker.logger).to receive(:info).with(/response.*200/)
|
71
74
|
expect(PactBroker.logger).to receive(:debug).with(/respbod/)
|
72
|
-
subject.execute
|
75
|
+
subject.execute(options)
|
73
76
|
end
|
74
77
|
|
75
78
|
describe "execution logs" do
|
76
|
-
before do
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
let(:logs) { subject.execute.logs }
|
81
79
|
|
82
80
|
it "logs the request method and path" do
|
83
81
|
expect(logs).to include "POST http://example.org/hook"
|
@@ -87,12 +85,16 @@ module PactBroker
|
|
87
85
|
expect(logs).to include "Content-Type: text/plain"
|
88
86
|
end
|
89
87
|
|
88
|
+
it "redacts potentially sensitive headers" do
|
89
|
+
expect(logs).to include "Authorization: [REDACTED]"
|
90
|
+
end
|
91
|
+
|
90
92
|
it "logs the request body" do
|
91
93
|
expect(logs).to include body
|
92
94
|
end
|
93
95
|
|
94
96
|
it "logs the response status" do
|
95
|
-
expect(logs).to include "HTTP/1.0
|
97
|
+
expect(logs).to include "HTTP/1.0 200"
|
96
98
|
end
|
97
99
|
|
98
100
|
it "logs the response headers" do
|
@@ -103,6 +105,20 @@ module PactBroker
|
|
103
105
|
expect(logs).to include "respbod"
|
104
106
|
end
|
105
107
|
|
108
|
+
context "when the response code is a success" do
|
109
|
+
it "does not log the failure_log_message" do
|
110
|
+
allow_any_instance_of(WebhookExecutionResult).to receive(:success?).and_return(true)
|
111
|
+
expect(logs).to_not include "oops"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when the response code is not successful" do
|
116
|
+
it "logs the failure_log_message" do
|
117
|
+
allow_any_instance_of(WebhookExecutionResult).to receive(:success?).and_return(false)
|
118
|
+
expect(logs).to include "oops"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
106
122
|
context "with basic auth" do
|
107
123
|
let(:username) { 'username' }
|
108
124
|
let(:password) { 'password' }
|
@@ -124,11 +140,11 @@ module PactBroker
|
|
124
140
|
basic_auth: [username, password],
|
125
141
|
:headers => {'Content-Type'=>'text/plain'},
|
126
142
|
:body => 'body').
|
127
|
-
to_return(:status =>
|
143
|
+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
128
144
|
end
|
129
145
|
|
130
146
|
it "uses the credentials" do
|
131
|
-
subject.execute
|
147
|
+
subject.execute(options)
|
132
148
|
expect(http_request_with_basic_auth).to have_been_made
|
133
149
|
end
|
134
150
|
end
|
@@ -140,11 +156,11 @@ module PactBroker
|
|
140
156
|
# webmock will set the request signature scheme to 'https' _only_ if the use_ssl option is set
|
141
157
|
stub_request(:post, "https://example.org/hook").
|
142
158
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body').
|
143
|
-
to_return(:status =>
|
159
|
+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
144
160
|
end
|
145
161
|
|
146
162
|
it "uses SSL" do
|
147
|
-
subject.execute
|
163
|
+
subject.execute(options)
|
148
164
|
expect(https_request).to have_been_made
|
149
165
|
end
|
150
166
|
end
|
@@ -155,11 +171,11 @@ module PactBroker
|
|
155
171
|
let!(:http_request) do
|
156
172
|
stub_request(:post, "http://example.org/hook").
|
157
173
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => body.to_json).
|
158
|
-
to_return(:status =>
|
174
|
+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
159
175
|
end
|
160
176
|
|
161
177
|
it "converts the body to JSON before submitting the request" do
|
162
|
-
subject.execute
|
178
|
+
subject.execute(options)
|
163
179
|
expect(http_request).to have_been_made
|
164
180
|
end
|
165
181
|
end
|
@@ -170,22 +186,22 @@ module PactBroker
|
|
170
186
|
let!(:http_request) do
|
171
187
|
stub_request(:post, "http://example.org/hook").
|
172
188
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => nil).
|
173
|
-
to_return(:status =>
|
189
|
+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
174
190
|
end
|
175
191
|
|
176
192
|
it "executes the request without a body" do
|
177
|
-
subject.execute
|
193
|
+
subject.execute(options)
|
178
194
|
expect(http_request).to have_been_made
|
179
195
|
end
|
180
196
|
end
|
181
197
|
|
182
198
|
context "when the request is successful" do
|
183
199
|
it "returns a WebhookExecutionResult with success=true" do
|
184
|
-
expect(subject.execute.success?).to be true
|
200
|
+
expect(subject.execute(options).success?).to be true
|
185
201
|
end
|
186
202
|
|
187
203
|
it "sets the response on the result" do
|
188
|
-
expect(subject.execute.response).to be_instance_of(Net::
|
204
|
+
expect(subject.execute(options).response).to be_instance_of(Net::HTTPOK)
|
189
205
|
end
|
190
206
|
end
|
191
207
|
|
@@ -198,11 +214,11 @@ module PactBroker
|
|
198
214
|
end
|
199
215
|
|
200
216
|
it "returns a WebhookExecutionResult with success=false" do
|
201
|
-
expect(subject.execute.success?).to be false
|
217
|
+
expect(subject.execute(options).success?).to be false
|
202
218
|
end
|
203
219
|
|
204
220
|
it "sets the response on the result" do
|
205
|
-
expect(subject.execute.response).to be_instance_of(Net::HTTPInternalServerError)
|
221
|
+
expect(subject.execute(options).response).to be_instance_of(Net::HTTPInternalServerError)
|
206
222
|
end
|
207
223
|
end
|
208
224
|
|
@@ -217,22 +233,22 @@ module PactBroker
|
|
217
233
|
it "logs the error" do
|
218
234
|
allow(PactBroker.logger).to receive(:error)
|
219
235
|
expect(PactBroker.logger).to receive(:error).with(/Error.*WebhookTestError.*blah/)
|
220
|
-
subject.execute
|
236
|
+
subject.execute(options)
|
221
237
|
end
|
222
238
|
|
223
239
|
it "returns a WebhookExecutionResult with success=false" do
|
224
|
-
expect(subject.execute.success?).to be false
|
240
|
+
expect(subject.execute(options).success?).to be false
|
225
241
|
end
|
226
242
|
|
227
243
|
it "returns a WebhookExecutionResult with an error" do
|
228
|
-
expect(subject.execute.error).to be_instance_of WebhookTestError
|
244
|
+
expect(subject.execute(options).error).to be_instance_of WebhookTestError
|
229
245
|
end
|
230
|
-
end
|
231
246
|
|
247
|
+
it "logs the failure_log_message" do
|
248
|
+
expect(logs).to include "oops"
|
249
|
+
end
|
250
|
+
end
|
232
251
|
end
|
233
|
-
|
234
252
|
end
|
235
|
-
|
236
253
|
end
|
237
|
-
|
238
254
|
end
|
@@ -10,6 +10,7 @@ module PactBroker
|
|
10
10
|
let(:consumer) { Pacticipant.new(name: 'Consumer')}
|
11
11
|
let(:provider) { Pacticipant.new(name: 'Provider')}
|
12
12
|
let(:request) { instance_double(PactBroker::Domain::WebhookRequest, execute: nil)}
|
13
|
+
let(:options) { double('options') }
|
13
14
|
subject { Webhook.new(request: request, consumer: consumer, provider: provider,) }
|
14
15
|
|
15
16
|
describe "description" do
|
@@ -21,19 +22,16 @@ module PactBroker
|
|
21
22
|
describe "execute" do
|
22
23
|
|
23
24
|
it "executes the request" do
|
24
|
-
expect(request).to receive(:execute)
|
25
|
-
subject.execute
|
25
|
+
expect(request).to receive(:execute).with(options)
|
26
|
+
subject.execute options
|
26
27
|
end
|
27
28
|
|
28
29
|
it "logs before and after" do
|
29
30
|
allow(PactBroker.logger).to receive(:info)
|
30
31
|
expect(PactBroker.logger).to receive(:info).with(/Executing/)
|
31
|
-
subject.execute
|
32
|
+
subject.execute options
|
32
33
|
end
|
33
|
-
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
37
36
|
end
|
38
|
-
|
39
37
|
end
|
@@ -104,11 +104,13 @@ module PactBroker
|
|
104
104
|
let(:verification) { instance_double("PactBroker::Domain::Verification")}
|
105
105
|
let(:pacts) { [pact]}
|
106
106
|
let(:webhooks) { [instance_double("PactBroker::Domain::Webhook")]}
|
107
|
+
let(:triggered_webhooks) { [instance_double("PactBroker::Webhooks::TriggeredWebhook")] }
|
107
108
|
|
108
109
|
before do
|
109
110
|
allow_any_instance_of(PactBroker::Pacts::Repository).to receive(:find_latest_pacts).and_return(pacts)
|
110
111
|
allow(PactBroker::Verifications::Service).to receive(:find_latest_verification_for).and_return(verification)
|
111
112
|
allow(PactBroker::Webhooks::Service).to receive(:find_by_consumer_and_provider).and_return(webhooks)
|
113
|
+
allow(PactBroker::Webhooks::Service).to receive(:find_latest_triggered_webhooks).and_return(triggered_webhooks)
|
112
114
|
end
|
113
115
|
|
114
116
|
it "retrieves the webhooks for the pact" do
|
@@ -139,7 +141,8 @@ module PactBroker
|
|
139
141
|
.create_consumer_version_tag("prod")
|
140
142
|
.create_pact
|
141
143
|
.create_webhook
|
142
|
-
.
|
144
|
+
.create_triggered_webhook
|
145
|
+
.create_deprecated_webhook_execution
|
143
146
|
.create_verification
|
144
147
|
end
|
145
148
|
|
@@ -171,6 +174,12 @@ module PactBroker
|
|
171
174
|
}.by(-1)
|
172
175
|
end
|
173
176
|
|
177
|
+
it "deletes the triggered webhooks" do
|
178
|
+
expect{ delete_consumer }.to change{
|
179
|
+
PactBroker::Webhooks::TriggeredWebhook.count
|
180
|
+
}.by(-1)
|
181
|
+
end
|
182
|
+
|
174
183
|
it "deletes the webhook executions" do
|
175
184
|
expect{ delete_consumer }.to change{
|
176
185
|
PactBroker::Webhooks::Execution.count
|
@@ -215,6 +224,12 @@ module PactBroker
|
|
215
224
|
}.by(-1)
|
216
225
|
end
|
217
226
|
|
227
|
+
it "deletes the triggered webhooks" do
|
228
|
+
expect{ delete_provider }.to change{
|
229
|
+
PactBroker::Webhooks::TriggeredWebhook.count
|
230
|
+
}.by(-1)
|
231
|
+
end
|
232
|
+
|
218
233
|
it "deletes the webhook executions" do
|
219
234
|
expect{ delete_provider }.to change{
|
220
235
|
PactBroker::Webhooks::Execution.count
|
@@ -90,7 +90,7 @@ module PactBroker
|
|
90
90
|
describe "update" do
|
91
91
|
|
92
92
|
let(:existing_pact) do
|
93
|
-
TestDataBuilder.new.create_pact_with_hierarchy
|
93
|
+
TestDataBuilder.new.create_pact_with_hierarchy("A Consumer", "1.2.3", "A Provider", original_json_content).and_return(:pact)
|
94
94
|
end
|
95
95
|
|
96
96
|
before do
|
@@ -358,6 +358,27 @@ module PactBroker
|
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|
361
|
+
describe "find_all_revisions" do
|
362
|
+
before do
|
363
|
+
TestDataBuilder.new
|
364
|
+
.create_pact_with_hierarchy("foo", "3.0.0", "bar")
|
365
|
+
.revise_pact
|
366
|
+
.create_pact_with_hierarchy(consumer_name, "1.2.3", provider_name)
|
367
|
+
.revise_pact
|
368
|
+
.create_consumer_version("4.5.6")
|
369
|
+
.create_pact
|
370
|
+
end
|
371
|
+
|
372
|
+
subject { Repository.new.find_all_revisions consumer_name, "1.2.3", provider_name }
|
373
|
+
|
374
|
+
it "returns all the revisions for the given pact version" do
|
375
|
+
expect(subject.size).to eq 2
|
376
|
+
expect(subject.first.consumer_name).to eq consumer_name
|
377
|
+
expect(subject.first.revision_number).to eq 1
|
378
|
+
expect(subject.last.revision_number).to eq 2
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
361
382
|
describe "find_previous_pact" do
|
362
383
|
before do
|
363
384
|
TestDataBuilder.new
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'pact_broker/pacts/service'
|
3
|
+
require 'pact_broker/pacts/pact_params'
|
4
|
+
|
3
5
|
|
4
6
|
module PactBroker
|
5
7
|
|
6
8
|
module Pacts
|
7
|
-
|
9
|
+
describe Service do
|
10
|
+
|
11
|
+
let(:td) { TestDataBuilder.new }
|
8
12
|
|
9
13
|
describe "find_distinct_pacts_between" do
|
10
14
|
let(:pact_1) { double('pact 1', json_content: 'content 1')}
|
@@ -61,6 +65,33 @@ module PactBroker
|
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
68
|
+
|
69
|
+
describe "delete" do
|
70
|
+
before do
|
71
|
+
td.create_pact_with_hierarchy
|
72
|
+
.create_webhook
|
73
|
+
.create_triggered_webhook
|
74
|
+
.create_webhook_execution
|
75
|
+
.create_deprecated_webhook_execution
|
76
|
+
.revise_pact
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:params) do
|
80
|
+
{
|
81
|
+
consumer_name: td.consumer.name,
|
82
|
+
provider_name: td.provider.name,
|
83
|
+
consumer_version_number: td.consumer_version.number
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
subject { Service.delete PactParams.new(PactBroker::Pacts::PactParams.new(params)) }
|
88
|
+
|
89
|
+
it "deletes the pact" do
|
90
|
+
expect { subject }.to change {
|
91
|
+
Pacts::PactPublication.where(id: td.pact.id ).count
|
92
|
+
}.by(-1)
|
93
|
+
end
|
94
|
+
end
|
64
95
|
end
|
65
96
|
end
|
66
97
|
end
|
@@ -62,6 +62,50 @@ module PactBroker
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
describe "webhooks" do
|
66
|
+
let(:domain_relationship) do
|
67
|
+
instance_double("PactBroker::Domain::Relationship",
|
68
|
+
webhook_status: webhook_status,
|
69
|
+
last_webhook_execution_date: DateTime.now - 1,
|
70
|
+
latest_pact: double("pact", consumer: consumer, provider: provider)
|
71
|
+
)
|
72
|
+
end
|
73
|
+
let(:webhook_status) { :none }
|
74
|
+
|
75
|
+
subject { Relationship.new(domain_relationship) }
|
76
|
+
|
77
|
+
context "when the webhooks_status is :none" do
|
78
|
+
its(:webhook_label) { is_expected.to eq "Create" }
|
79
|
+
its(:webhook_status) { is_expected.to eq "" }
|
80
|
+
its(:webhook_url) { is_expected.to end_with "/webhooks/provider/Provider%20Name/consumer/Consumer%20Name"}
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when the webhooks_status is :success" do
|
84
|
+
let(:webhook_status) { :success }
|
85
|
+
its(:webhook_label) { is_expected.to eq "1 day ago" }
|
86
|
+
its(:webhook_status) { is_expected.to eq "success" }
|
87
|
+
its(:webhook_url) { is_expected.to end_with "/webhooks/provider/Provider%20Name/consumer/Consumer%20Name/status"}
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when the webhooks_status is :failure" do
|
91
|
+
let(:webhook_status) { :failure }
|
92
|
+
its(:webhook_label) { is_expected.to eq "1 day ago" }
|
93
|
+
its(:webhook_status) { is_expected.to eq "danger" }
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when the webhooks_status is :not_run" do
|
97
|
+
let(:webhook_status) { :not_run }
|
98
|
+
its(:webhook_label) { is_expected.to eq "Not run" }
|
99
|
+
its(:webhook_status) { is_expected.to eq "" }
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when the webhooks_status is :retrying" do
|
103
|
+
let(:webhook_status) { :retrying }
|
104
|
+
its(:webhook_label) { is_expected.to eq "Retrying" }
|
105
|
+
its(:webhook_status) { is_expected.to eq "warning" }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
65
109
|
describe "<=>" do
|
66
110
|
|
67
111
|
let(:relationship_model_4) { double("PactBroker::Domain::Relationship", consumer_name: "A", provider_name: "X") }
|
@@ -101,6 +101,25 @@ module PactBroker
|
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "#find_latest_verification_for" do
|
104
|
+
context "when there is a revision" do
|
105
|
+
before do
|
106
|
+
TestDataBuilder.new
|
107
|
+
.create_provider("Provider1")
|
108
|
+
.create_consumer("Consumer1")
|
109
|
+
.create_consumer_version("1.2.3")
|
110
|
+
.create_pact
|
111
|
+
.create_verification(number: 1, provider_version: "2.3.4")
|
112
|
+
.revise_pact
|
113
|
+
.create_verification(number: 1, provider_version: "7.8.9")
|
114
|
+
end
|
115
|
+
|
116
|
+
subject { Repository.new.find_latest_verification_for("Consumer1", "Provider1")}
|
117
|
+
|
118
|
+
it "finds the latest verifications for the given consumer version" do
|
119
|
+
expect(subject.provider_version).to eq "7.8.9"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
104
123
|
context "when no tag is specified" do
|
105
124
|
before do
|
106
125
|
TestDataBuilder.new
|
@@ -23,7 +23,7 @@ module PactBroker
|
|
23
23
|
|
24
24
|
describe "#create" do
|
25
25
|
let(:params) { {'success' => true, 'providerApplicationVersion' => '4.5.6'} }
|
26
|
-
let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy }
|
26
|
+
let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy.and_return(:pact) }
|
27
27
|
let(:create_verification) { subject.create 3, params, pact }
|
28
28
|
|
29
29
|
it "logs the creation" do
|