pact_broker 2.31.0 → 2.32.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/db/migrations/20190509_create_version_sequence.rb +8 -0
- data/db/migrations/20190510_set_version_sequence.rb +9 -0
- data/db/migrations/20190511_create_integrations_view.rb +19 -0
- data/db/migrations/20190523_add_enabled_column_to_webhooks.rb +5 -0
- data/db/migrations/20190524_set_webhooks_enabled.rb +10 -0
- data/db/migrations/20190525_add_description_column_to_webhooks.rb +5 -0
- data/lib/pact_broker/api.rb +3 -0
- data/lib/pact_broker/api/decorators/base_decorator.rb +0 -3
- data/lib/pact_broker/api/decorators/integration_decorator.rb +40 -0
- data/lib/pact_broker/api/decorators/integrations_decorator.rb +19 -0
- data/lib/pact_broker/api/decorators/pact_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/pact_details_decorator.rb +1 -6
- data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +12 -0
- data/lib/pact_broker/api/decorators/verifiable_pacts_decorator.rb +20 -0
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +5 -1
- data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/webhooks_decorator.rb +2 -2
- data/lib/pact_broker/api/pact_broker_urls.rb +37 -3
- data/lib/pact_broker/api/resources/base_resource.rb +4 -0
- data/lib/pact_broker/api/resources/dashboard.rb +1 -1
- data/lib/pact_broker/api/resources/integrations.rb +10 -2
- data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +8 -14
- data/lib/pact_broker/api/resources/pact.rb +15 -3
- data/lib/pact_broker/api/resources/verification.rb +0 -2
- data/lib/pact_broker/api/resources/verifications.rb +18 -1
- data/lib/pact_broker/api/resources/webhook.rb +1 -1
- data/lib/pact_broker/api/resources/webhook_execution.rb +18 -9
- data/lib/pact_broker/app.rb +10 -11
- data/lib/pact_broker/db.rb +2 -2
- data/lib/pact_broker/db/data_migrations/helpers.rb +11 -0
- data/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb +29 -0
- data/lib/pact_broker/db/data_migrations/set_webhooks_enabled.rb +17 -0
- data/lib/pact_broker/db/migrate_data.rb +2 -0
- data/lib/pact_broker/db/seed_example_data.rb +6 -3
- data/lib/pact_broker/domain/order_versions.rb +14 -1
- data/lib/pact_broker/domain/verification.rb +4 -0
- data/lib/pact_broker/domain/webhook.rb +13 -3
- data/lib/pact_broker/domain/webhook_request.rb +3 -2
- data/lib/pact_broker/index/service.rb +3 -0
- data/lib/pact_broker/integrations/integration.rb +10 -0
- data/lib/pact_broker/integrations/service.rb +5 -0
- data/lib/pact_broker/matrix/parse_query.rb +2 -0
- data/lib/pact_broker/matrix/row.rb +8 -0
- data/lib/pact_broker/matrix/service.rb +1 -2
- data/lib/pact_broker/pacts/service.rb +16 -9
- data/lib/pact_broker/test/test_data_builder.rb +6 -2
- data/lib/pact_broker/verifications/sequence.rb +0 -2
- data/lib/pact_broker/verifications/service.rb +10 -2
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/sequence.rb +38 -0
- data/lib/pact_broker/webhooks/job.rb +19 -7
- data/lib/pact_broker/webhooks/render.rb +30 -13
- data/lib/pact_broker/webhooks/repository.rb +3 -4
- data/lib/pact_broker/webhooks/service.rb +60 -34
- data/lib/pact_broker/webhooks/trigger_service.rb +6 -6
- data/lib/pact_broker/webhooks/webhook.rb +9 -1
- data/lib/pact_broker/webhooks/webhook_request_template.rb +11 -7
- data/lib/rack/pact_broker/database_transaction.rb +6 -2
- data/script/publish-new.sh +23 -1
- data/script/publish.sh +13 -4
- data/script/seed.rb +53 -52
- data/spec/features/create_webhook_spec.rb +2 -0
- data/spec/features/execute_webhook_spec.rb +4 -3
- data/spec/features/get_integrations_spec.rb +17 -0
- data/spec/features/get_pacts_to_verify_spec.rb +7 -3
- data/spec/features/publish_verification_spec.rb +8 -1
- data/spec/features/update_webhook_spec.rb +47 -0
- data/spec/integration/webhooks/certificate_spec.rb +1 -1
- data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +12 -0
- data/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb +82 -0
- data/spec/lib/pact_broker/api/decorators/integrations_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +12 -4
- data/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +30 -0
- data/spec/lib/pact_broker/api/decorators/verifiable_pacts_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +20 -1
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +0 -4
- data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +5 -4
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +64 -1
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -3
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +40 -10
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -3
- data/spec/lib/pact_broker/app_spec.rb +28 -4
- data/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb +68 -0
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +1 -4
- data/spec/lib/pact_broker/domain/webhook_spec.rb +10 -6
- data/spec/lib/pact_broker/matrix/parse_query_spec.rb +15 -7
- data/spec/lib/pact_broker/pacts/service_spec.rb +13 -5
- data/spec/lib/pact_broker/verifications/service_spec.rb +15 -3
- data/spec/lib/pact_broker/versions/repository_spec.rb +1 -1
- data/spec/lib/pact_broker/webhooks/job_spec.rb +52 -15
- data/spec/lib/pact_broker/webhooks/render_spec.rb +28 -7
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +23 -32
- data/spec/lib/pact_broker/webhooks/service_spec.rb +186 -62
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +6 -5
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +12 -5
- data/spec/lib/rack/pact_broker/database_transaction_spec.rb +10 -0
- data/spec/lib/rack/pact_broker/ui_request_filter_spec.rb +9 -0
- data/spec/migrations/23_pact_versions_spec.rb +7 -1
- data/spec/support/database_cleaner.rb +11 -1
- data/spec/support/metadata_test_server.rb +40 -0
- data/spec/support/verification_job.rb +34 -0
- data/spec/support/webhook_endpoint_middleware.rb +22 -0
- metadata +37 -2
@@ -9,21 +9,21 @@ module PactBroker
|
|
9
9
|
extend PactBroker::Services
|
10
10
|
include PactBroker::Logging
|
11
11
|
|
12
|
-
def trigger_webhooks_for_new_pact
|
13
|
-
webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED
|
12
|
+
def trigger_webhooks_for_new_pact(pact, webhook_options)
|
13
|
+
webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED, webhook_options
|
14
14
|
if pact_is_new_or_newly_tagged_or_pact_has_changed_since_previous_version?(pact)
|
15
|
-
webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
|
15
|
+
webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, webhook_options
|
16
16
|
else
|
17
17
|
logger.debug "Pact content has not changed since previous version, not triggering webhooks for changed content"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def trigger_webhooks_for_updated_pact(existing_pact, updated_pact)
|
22
|
-
webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED
|
21
|
+
def trigger_webhooks_for_updated_pact(existing_pact, updated_pact, webhook_options)
|
22
|
+
webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED, webhook_options
|
23
23
|
# TODO this should use the sha!
|
24
24
|
if existing_pact.pact_version_sha != updated_pact.pact_version_sha
|
25
25
|
logger.debug "Existing pact for version #{existing_pact.consumer_version_number} has been updated with new content, triggering webhooks for changed content"
|
26
|
-
webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
|
26
|
+
webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, webhook_options
|
27
27
|
else
|
28
28
|
logger.debug "Pact content has not changed since previous revision, not triggering webhooks for changed content"
|
29
29
|
end
|
@@ -15,6 +15,10 @@ module PactBroker
|
|
15
15
|
|
16
16
|
dataset_module do
|
17
17
|
include PactBroker::Repositories::Helpers
|
18
|
+
|
19
|
+
def enabled
|
20
|
+
where(enabled: true)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def before_destroy
|
@@ -42,10 +46,12 @@ module PactBroker
|
|
42
46
|
def to_domain
|
43
47
|
Domain::Webhook.new(
|
44
48
|
uuid: uuid,
|
49
|
+
description: description,
|
45
50
|
consumer: consumer,
|
46
51
|
provider: provider,
|
47
52
|
events: events,
|
48
53
|
request: Webhooks::WebhookRequestTemplate.new(request_attributes),
|
54
|
+
enabled: enabled,
|
49
55
|
created_at: created_at,
|
50
56
|
updated_at: updated_at)
|
51
57
|
end
|
@@ -81,17 +87,19 @@ module PactBroker
|
|
81
87
|
def self.properties_hash_from_domain webhook
|
82
88
|
is_json_request_body = !(String === webhook.request.body || webhook.request.body.nil?) # Can't rely on people to set content type
|
83
89
|
{
|
90
|
+
description: webhook.description,
|
84
91
|
method: webhook.request.method,
|
85
92
|
url: webhook.request.url,
|
86
93
|
username: webhook.request.username,
|
87
94
|
password: not_plain_text_password(webhook.request.password),
|
95
|
+
enabled: webhook.enabled.nil? ? true : webhook.enabled,
|
88
96
|
body: (is_json_request_body ? webhook.request.body.to_json : webhook.request.body),
|
89
97
|
is_json_request_body: is_json_request_body
|
90
98
|
}
|
91
99
|
end
|
92
100
|
end
|
93
101
|
|
94
|
-
Webhook.plugin :timestamps, :
|
102
|
+
Webhook.plugin :timestamps, update_on_create: true
|
95
103
|
|
96
104
|
class WebhookHeader < Sequel::Model
|
97
105
|
associate(:many_to_one, :webhook, :class => "PactBroker::Repositories::Webhook", :key => :webhook_id, :primary_key => :id)
|
@@ -22,7 +22,7 @@ module PactBroker
|
|
22
22
|
@url = attributes[:url]
|
23
23
|
@username = attributes[:username]
|
24
24
|
@password = attributes[:password]
|
25
|
-
@headers = attributes[:headers] || {}
|
25
|
+
@headers = Rack::Utils::HeaderHash.new(attributes[:headers] || {})
|
26
26
|
@body = attributes[:body]
|
27
27
|
@uuid = attributes[:uuid]
|
28
28
|
end
|
@@ -30,23 +30,23 @@ module PactBroker
|
|
30
30
|
def build(context)
|
31
31
|
attributes = {
|
32
32
|
method: http_method,
|
33
|
-
url: build_url(context[:pact], context[:verification], context[:
|
33
|
+
url: build_url(context[:pact], context[:verification], context[:webhook_context]),
|
34
34
|
headers: headers,
|
35
35
|
username: username,
|
36
36
|
password: password,
|
37
37
|
uuid: uuid,
|
38
|
-
body: build_body(context[:pact], context[:verification], context[:
|
38
|
+
body: build_body(context[:pact], context[:verification], context[:webhook_context])
|
39
39
|
}
|
40
40
|
PactBroker::Domain::WebhookRequest.new(attributes)
|
41
41
|
end
|
42
42
|
|
43
|
-
def build_url(pact, verification,
|
44
|
-
URI(PactBroker::Webhooks::Render.call(url, pact, verification,
|
43
|
+
def build_url(pact, verification, webhook_context)
|
44
|
+
URI(PactBroker::Webhooks::Render.call(url, pact, verification, webhook_context){ | value | CGI::escape(value) if !value.nil? } ).to_s
|
45
45
|
end
|
46
46
|
|
47
|
-
def build_body(pact, verification,
|
47
|
+
def build_body(pact, verification, webhook_context)
|
48
48
|
body_string = String === body ? body : body.to_json
|
49
|
-
PactBroker::Webhooks::Render.call(body_string, pact, verification,
|
49
|
+
PactBroker::Webhooks::Render.call(body_string, pact, verification, webhook_context)
|
50
50
|
end
|
51
51
|
|
52
52
|
def description
|
@@ -64,6 +64,10 @@ module PactBroker
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
def headers= headers
|
68
|
+
@headers = Rack::Utils::HeaderHash.new(headers)
|
69
|
+
end
|
70
|
+
|
67
71
|
private
|
68
72
|
|
69
73
|
def to_s
|
@@ -22,14 +22,18 @@ module Rack
|
|
22
22
|
def call env
|
23
23
|
set_database_connector
|
24
24
|
if use_transaction? env
|
25
|
-
call_with_transaction
|
25
|
+
call_with_transaction(add_database_connector(env))
|
26
26
|
else
|
27
|
-
call_without_transaction
|
27
|
+
call_without_transaction(add_database_connector(env))
|
28
28
|
end
|
29
29
|
ensure
|
30
30
|
clear_database_connector
|
31
31
|
end
|
32
32
|
|
33
|
+
def add_database_connector(env)
|
34
|
+
env.merge("pactbroker.database_connector" => @default_database_connector)
|
35
|
+
end
|
36
|
+
|
33
37
|
def use_transaction? env
|
34
38
|
TRANS_METHODS.include? env[REQUEST_METHOD]
|
35
39
|
end
|
data/script/publish-new.sh
CHANGED
@@ -1,9 +1,31 @@
|
|
1
1
|
set -e
|
2
|
+
|
2
3
|
BODY=$(ruby -e "require 'json'; j = JSON.parse(File.read('script/foo-bar.json')); j['interactions'][0]['providerState'] = 'it is ' + Time.now.to_s; puts j.to_json")
|
3
4
|
latest_url=$(curl http://localhost:9292/pacts/provider/Bar/consumer/Foo/latest | jq -r ._links.self.href)
|
4
5
|
next_version=$(echo ${latest_url} | ruby -e "version = ARGF.read[/\d+\.\d+\.\d+/]; require 'semver'; puts SemVer.parse(version).tap{ | v| v.minor = v.minor + 1}.format('%M.%m.%p')")
|
6
|
+
|
7
|
+
curl -v -XPUT \
|
8
|
+
-H "Content-Length: 0" \
|
9
|
+
-H "Content-Type: application/json" \
|
10
|
+
http://localhost:9292/pacticipants/Foo/versions/${next_version}/tags/dev
|
11
|
+
|
5
12
|
echo ${BODY} > tmp.json
|
6
13
|
curl -v -XPUT \-H "Content-Type: application/json" -d@tmp.json \
|
7
14
|
http://localhost:9292/pacts/provider/Bar/consumer/Foo/version/${next_version}
|
15
|
+
|
16
|
+
|
17
|
+
sleep 3
|
18
|
+
|
19
|
+
|
20
|
+
curl -v -XPUT \
|
21
|
+
-H "Content-Length: 0" \
|
22
|
+
-H "Content-Type: application/json" \
|
23
|
+
http://localhost:9292/pacticipants/Foo/versions/${next_version}/tags/prod
|
24
|
+
|
25
|
+
next_next_version=$(echo ${next_version} | ruby -e "version = ARGF.read[/\d+\.\d+\.\d+/]; require 'semver'; puts SemVer.parse(version).tap{ | v| v.minor = v.minor + 1}.format('%M.%m.%p')")
|
26
|
+
|
27
|
+
curl -v -XPUT \-H "Content-Type: application/json" -d@tmp.json \
|
28
|
+
http://localhost:9292/pacts/provider/Bar/consumer/Foo/version/${next_next_version}
|
29
|
+
|
8
30
|
rm tmp.json
|
9
|
-
echo ""
|
31
|
+
echo ""
|
data/script/publish.sh
CHANGED
@@ -1,19 +1,28 @@
|
|
1
1
|
#!/bin/sh
|
2
2
|
function finish {
|
3
|
-
rm -rf
|
3
|
+
rm -rf $tmpfile
|
4
4
|
}
|
5
5
|
trap finish EXIT
|
6
6
|
|
7
7
|
set -x
|
8
8
|
|
9
|
+
consumer_version="1.0.$(ruby -e "puts (rand * 10).to_i")"
|
9
10
|
consumer=${1:-Foo}
|
10
11
|
provider=${2:-Bar}
|
11
12
|
escaped_consumer=$(echo $consumer | ruby -e "require 'uri'; puts URI.encode(ARGF.read.strip)")
|
12
13
|
escaped_provider=$(echo $provider | ruby -e "require 'uri'; puts URI.encode(ARGF.read.strip)")
|
13
14
|
echo $consumer $provider
|
15
|
+
|
16
|
+
curl -v -XPUT \
|
17
|
+
-H "Content-Length: 0" \
|
18
|
+
-H "Content-Type: application/json" \
|
19
|
+
http://localhost:9292/pacticipants/${escaped_consumer}/versions/${consumer_version}/tags/dev
|
20
|
+
|
21
|
+
|
14
22
|
body=$(cat script/foo-bar.json | sed "s/Foo/${consumer}/" | sed "s/Bar/${provider}/")
|
15
|
-
|
23
|
+
tmpfile=$(mktemp)
|
24
|
+
echo $body > $tmpfile
|
16
25
|
curl -v -XPUT \-H "Content-Type: application/json" \
|
17
|
-
-d
|
18
|
-
http://127.0.0.1:9292/pacts/provider/${escaped_provider}/consumer/${escaped_consumer}/version
|
26
|
+
-d@$tmpfile \
|
27
|
+
http://127.0.0.1:9292/pacts/provider/${escaped_provider}/consumer/${escaped_consumer}/version/${consumer_version}
|
19
28
|
echo ""
|
data/script/seed.rb
CHANGED
@@ -14,7 +14,7 @@ DATABASE_CREDENTIALS = {logger: Logger.new($stdout), adapter: "sqlite", database
|
|
14
14
|
connection = Sequel.connect(DATABASE_CREDENTIALS)
|
15
15
|
connection.timezone = :utc
|
16
16
|
# Uncomment these lines to open a pry session for inspecting the database
|
17
|
-
|
17
|
+
|
18
18
|
# require 'pry'; pry(binding);
|
19
19
|
# exit
|
20
20
|
|
@@ -44,54 +44,55 @@ webhook_body = {
|
|
44
44
|
}
|
45
45
|
|
46
46
|
TestDataBuilder.new
|
47
|
-
.create_global_webhook(method: '
|
48
|
-
.
|
49
|
-
.
|
50
|
-
.
|
51
|
-
.
|
52
|
-
.
|
53
|
-
.
|
54
|
-
.
|
55
|
-
.
|
56
|
-
.
|
57
|
-
.
|
58
|
-
.
|
59
|
-
.
|
60
|
-
.
|
61
|
-
|
62
|
-
.
|
63
|
-
.
|
64
|
-
.
|
65
|
-
.
|
66
|
-
|
67
|
-
.
|
68
|
-
.
|
69
|
-
.
|
70
|
-
.
|
71
|
-
.
|
72
|
-
.
|
73
|
-
.
|
74
|
-
.
|
75
|
-
.
|
76
|
-
|
77
|
-
.
|
78
|
-
.
|
79
|
-
.
|
80
|
-
.
|
81
|
-
.
|
82
|
-
.
|
83
|
-
.
|
84
|
-
.
|
85
|
-
.create_consumer_version_tag("
|
86
|
-
.
|
87
|
-
.
|
88
|
-
.
|
89
|
-
.
|
90
|
-
.
|
91
|
-
.
|
92
|
-
.
|
93
|
-
.
|
94
|
-
.
|
95
|
-
.
|
96
|
-
.
|
97
|
-
.
|
47
|
+
.create_global_webhook(method: 'POST', url: "http://localhost:9292/pact-changed-webhook", body: webhook_body.to_json)
|
48
|
+
.create_global_verification_webhook(method: 'POST', url: "http://localhost:9292/verification-published-webhook", body: webhook_body.to_json)
|
49
|
+
# .create_certificate(path: 'spec/fixtures/certificates/self-signed.badssl.com.pem')
|
50
|
+
# .create_consumer("Bethtest")
|
51
|
+
# .create_verification_webhook(method: 'GET', url: "http://localhost:9292", body: webhook_body, username: "foo", password: "bar", headers: {"Accept" => "application/json"})
|
52
|
+
# .create_consumer("Foo")
|
53
|
+
# .create_label("microservice")
|
54
|
+
# .create_provider("Bar")
|
55
|
+
# .create_label("microservice")
|
56
|
+
# .create_verification_webhook(method: 'GET', url: "http://example.org")
|
57
|
+
# .create_consumer_webhook(method: 'GET', url: 'https://www.google.com.au', event_names: ['provider_verification_published'])
|
58
|
+
# .create_provider_webhook(method: 'GET', url: 'https://theage.com.au')
|
59
|
+
# .create_webhook(method: 'GET', url: 'https://self-signed.badssl.com')
|
60
|
+
# .create_consumer_version("1.2.100")
|
61
|
+
# .create_pact
|
62
|
+
# .create_verification(provider_version: "1.4.234", success: true, execution_date: DateTime.now - 15)
|
63
|
+
# .revise_pact
|
64
|
+
# .create_consumer_version("1.2.101")
|
65
|
+
# .create_consumer_version_tag('prod')
|
66
|
+
# .create_pact
|
67
|
+
# .create_verification(provider_version: "9.9.10", success: false, execution_date: DateTime.now - 15)
|
68
|
+
# .create_consumer_version("1.2.102")
|
69
|
+
# .create_pact(created_at: (Date.today - 7).to_datetime)
|
70
|
+
# .create_verification(provider_version: "9.9.9", success: true, execution_date: DateTime.now - 14)
|
71
|
+
# .create_provider("Animals")
|
72
|
+
# .create_webhook(method: 'GET', url: 'http://localhost:9393/')
|
73
|
+
# .create_pact(created_at: (Time.now - 140).to_datetime)
|
74
|
+
# .create_verification(provider_version: "2.0.366", execution_date: Date.today - 2) #changed
|
75
|
+
# .create_provider("Wiffles")
|
76
|
+
# .create_pact
|
77
|
+
# .create_verification(provider_version: "3.6.100", success: false, execution_date: Date.today - 7)
|
78
|
+
# .create_provider("Hello World App")
|
79
|
+
# .create_consumer_version("1.2.107")
|
80
|
+
# .create_pact(created_at: (Date.today - 1).to_datetime)
|
81
|
+
# .create_consumer("The Android App")
|
82
|
+
# .create_provider("The back end")
|
83
|
+
# .create_webhook(method: 'GET', url: 'http://localhost:9393/')
|
84
|
+
# .create_consumer_version("1.2.106")
|
85
|
+
# .create_consumer_version_tag("production")
|
86
|
+
# .create_consumer_version_tag("feat-x")
|
87
|
+
# .create_pact
|
88
|
+
# .create_consumer("Some other app")
|
89
|
+
# .create_provider("A service")
|
90
|
+
# .create_webhook(method: 'GET', url: 'http://localhost:9393/')
|
91
|
+
# .create_triggered_webhook(status: 'success')
|
92
|
+
# .create_webhook_execution
|
93
|
+
# .create_webhook(method: 'POST', url: 'http://foo:9393/')
|
94
|
+
# .create_triggered_webhook(status: 'failure')
|
95
|
+
# .create_webhook_execution
|
96
|
+
# .create_consumer_version("1.2.106")
|
97
|
+
# .create_pact(created_at: (Date.today - 26).to_datetime)
|
98
|
+
# .create_verification(provider_version: "4.8.152", execution_date: DateTime.now)
|
@@ -19,9 +19,10 @@ describe "Execute a webhook" do
|
|
19
19
|
|
20
20
|
context "when the execution is successful" do
|
21
21
|
let!(:request) do
|
22
|
-
stub_request(:post, /http/).with(body:
|
22
|
+
stub_request(:post, /http/).with(body: expected_webhook_url).to_return(:status => 200, body: response_body)
|
23
23
|
end
|
24
24
|
|
25
|
+
let(:expected_webhook_url) { %r{http://example.org/pacts/provider/Bar/consumer/Foo/pact-version/.*/metadata/Y29uc3VtZXJfdmVyc2lvbl9udW1iZXI9MQ==} }
|
25
26
|
let(:response_body) { "webhook-response-body" }
|
26
27
|
|
27
28
|
it "performs the HTTP request" do
|
@@ -81,8 +82,8 @@ describe "Execute a webhook" do
|
|
81
82
|
|
82
83
|
subject { post path; last_response }
|
83
84
|
|
84
|
-
it "returns a
|
85
|
-
expect(subject.status).to be
|
85
|
+
it "returns a 200 response" do
|
86
|
+
expect(subject.status).to be 200
|
86
87
|
end
|
87
88
|
|
88
89
|
it "does not save a TriggeredWebhook" do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe "Get integrations dot file" do
|
2
|
+
before do
|
3
|
+
TestDataBuilder.new
|
4
|
+
.create_pact_with_hierarchy("Foo", "1", "Bar")
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:path) { "/integrations" }
|
8
|
+
let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) }
|
9
|
+
|
10
|
+
subject { get path, nil, {'HTTP_ACCEPT' => 'application/hal+json' } }
|
11
|
+
|
12
|
+
it { is_expected.to be_a_hal_json_success_response }
|
13
|
+
|
14
|
+
it "returns a json body with embedded integrations" do
|
15
|
+
expect(JSON.parse(subject.body)["_embedded"]["integrations"]).to be_a(Array)
|
16
|
+
end
|
17
|
+
end
|
@@ -12,7 +12,9 @@ describe "fetching pacts to verify", pending: 'not yet implemented' do
|
|
12
12
|
# eg. if content has been verified on git branch (broker tag) feat-2,
|
13
13
|
# it's still pending on master, and shouldn't fail the build
|
14
14
|
{
|
15
|
-
|
15
|
+
protocol: "http1", # other option is "message"
|
16
|
+
include_other_pending: true, # whether or not to include pending pacts not already specified by the consumer_version_tags('head' pacts that have not yet been successfully verified)
|
17
|
+
provider_version_tags: [{ name: "feat-2" }], # the provider tags that will be applied to this app version when the results are published
|
16
18
|
consumer_version_tags: [
|
17
19
|
{ name: "feat-1", fallback: "master" }, # allow a fallback to be provided for the "branch mirroring" workflow
|
18
20
|
{ name: "test", required: true }, # default to optional or required??? Ron?
|
@@ -30,8 +32,10 @@ describe "fetching pacts to verify", pending: 'not yet implemented' do
|
|
30
32
|
end
|
31
33
|
|
32
34
|
it "returns a list of links to the pacts" do
|
33
|
-
expect(response_body_hash[:
|
35
|
+
expect(response_body_hash[:_embedded][:'pacts']).to be_instance_of(Array)
|
34
36
|
end
|
35
37
|
|
36
|
-
it "indicates whether a pact is pending or not"
|
38
|
+
it "indicates whether a pact is pending or not" do
|
39
|
+
expect(response_body_hash[:_embedded][:'pacts'].first[:pending]).to be true
|
40
|
+
end
|
37
41
|
end
|
@@ -7,8 +7,15 @@ describe "Recording a pact verification" do
|
|
7
7
|
let(:verification_content) { load_fixture('verification.json') }
|
8
8
|
let(:parsed_response_body) { JSON.parse(subject.body) }
|
9
9
|
let(:pact) { td.pact }
|
10
|
+
let(:rack_env) do
|
11
|
+
{
|
12
|
+
'CONTENT_TYPE' => 'application/json',
|
13
|
+
'HTTP_ACCEPT' => 'application/hal+json',
|
14
|
+
'pactbroker.database_connector' => lambda { |&block| block.call }
|
15
|
+
}
|
16
|
+
end
|
10
17
|
|
11
|
-
subject { post path, verification_content,
|
18
|
+
subject { post path, verification_content, rack_env; last_response }
|
12
19
|
|
13
20
|
before do
|
14
21
|
td.create_provider("Provider")
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'support/test_data_builder'
|
2
|
+
|
3
|
+
describe "Updating a webhook" do
|
4
|
+
let(:webhook) do
|
5
|
+
TestDataBuilder.new
|
6
|
+
.create_pact_with_hierarchy("Some Consumer", "1", "Some Provider")
|
7
|
+
.create_global_webhook
|
8
|
+
.and_return(:webhook)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
|
12
|
+
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
|
13
|
+
let(:webhook_json) { webhook_hash.to_json }
|
14
|
+
let(:webhook_hash) do
|
15
|
+
{
|
16
|
+
description: "trigger build",
|
17
|
+
consumer: {
|
18
|
+
name: "Some Consumer"
|
19
|
+
},
|
20
|
+
enabled: false,
|
21
|
+
events: [{
|
22
|
+
name: 'contract_published'
|
23
|
+
}],
|
24
|
+
request: {
|
25
|
+
method: 'POST',
|
26
|
+
url: 'https://example.org',
|
27
|
+
headers: {
|
28
|
+
:"Content-Type" => "application/json"
|
29
|
+
},
|
30
|
+
body: {
|
31
|
+
a: 'body'
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
subject { put(path, webhook_json, headers) }
|
38
|
+
|
39
|
+
let(:path) { "/webhooks/#{webhook.uuid}" }
|
40
|
+
|
41
|
+
context "with valid attributes" do
|
42
|
+
it "returns the newly created webhook" do
|
43
|
+
subject
|
44
|
+
expect(response_body).to include description: "trigger build"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|