pact_broker 1.18.0 → 2.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -9
- data/DEVELOPER_DOCUMENTATION.md +53 -0
- data/README.md +13 -13
- data/db/migrations/23_create_pact_contents_table.rb +19 -0
- data/db/migrations/24_populate_pact_contents.rb +9 -0
- data/db/migrations/25_populate_pact_contents_pacticipants.rb +7 -0
- data/db/migrations/26_make_pc_pacticipants_mandatory.rb +8 -0
- data/db/migrations/27_create_pact_publications.rb +18 -0
- data/db/migrations/28_populate_pact_publications.rb +13 -0
- data/db/migrations/29_recreate_all_pacts.rb +16 -0
- data/db/migrations/30_drop_pacts.rb +8 -0
- data/db/migrations/31_drop_pact_version_contents.rb +5 -0
- data/db/migrations/32_rename_pact_contents.rb +5 -0
- data/db/migrations/33_recreate_all_pacts.rb +52 -0
- data/db/migrations/34_recreate_latest_tagged_pacts.rb +23 -0
- data/db/migrations/35_create_verifications.rb +15 -0
- data/db/migrations/36_create_latest_verifications.rb +14 -0
- data/db/pact_broker_database.sqlite3 +0 -0
- data/lib/pact_broker/api.rb +25 -10
- data/lib/pact_broker/api/contracts/verification_contract.rb +41 -0
- data/lib/pact_broker/api/decorators/pact_decorator.rb +7 -0
- data/lib/pact_broker/api/decorators/pact_version_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/representable_pact.rb +4 -3
- data/lib/pact_broker/api/decorators/timestamps.rb +1 -1
- data/lib/pact_broker/api/decorators/verification_decorator.rb +30 -0
- data/lib/pact_broker/api/decorators/verifications_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/version_decorator.rb +14 -0
- data/lib/pact_broker/api/decorators/versions_decorator.rb +1 -1
- data/lib/pact_broker/api/pact_broker_urls.rb +41 -2
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +1 -1
- data/lib/pact_broker/api/resources/base_resource.rb +11 -2
- data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +39 -0
- data/lib/pact_broker/api/resources/pacticipants.rb +1 -1
- data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
- data/lib/pact_broker/api/resources/verifications.rb +67 -0
- data/lib/pact_broker/api/resources/versions.rb +1 -1
- data/lib/pact_broker/api/resources/webhooks.rb +1 -1
- data/lib/pact_broker/app.rb +0 -2
- data/lib/pact_broker/configuration.rb +1 -4
- data/lib/pact_broker/doc/views/latest-verifications.markdown +7 -0
- data/lib/pact_broker/doc/views/publish-verification.markdown +14 -0
- data/lib/pact_broker/domain.rb +1 -1
- data/lib/pact_broker/domain/order_versions.rb +5 -15
- data/lib/pact_broker/domain/pact.rb +10 -2
- data/lib/pact_broker/domain/relationship.rb +31 -4
- data/lib/pact_broker/domain/verification.rb +77 -0
- data/lib/pact_broker/domain/version.rb +6 -1
- data/lib/pact_broker/domain/webhook.rb +1 -0
- data/lib/pact_broker/domain/webhook_request.rb +4 -6
- data/lib/pact_broker/locale/en.yml +2 -1
- data/lib/pact_broker/logging.rb +0 -4
- data/lib/pact_broker/pacticipants/repository.rb +1 -2
- data/lib/pact_broker/pacticipants/service.rb +11 -5
- data/lib/pact_broker/pacts/all_pact_publications.rb +96 -0
- data/lib/pact_broker/pacts/all_pacts.rb +4 -89
- data/lib/pact_broker/pacts/diff.rb +2 -2
- data/lib/pact_broker/pacts/latest_pact_publications.rb +11 -0
- data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +11 -0
- data/lib/pact_broker/pacts/latest_pacts.rb +1 -0
- data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +11 -0
- data/lib/pact_broker/pacts/pact_params.rb +11 -1
- data/lib/pact_broker/pacts/pact_publication.rb +50 -0
- data/lib/pact_broker/pacts/pact_version.rb +39 -0
- data/lib/pact_broker/pacts/repository.rb +46 -36
- data/lib/pact_broker/pacts/service.rb +2 -2
- data/lib/pact_broker/repositories.rb +5 -0
- data/lib/pact_broker/services.rb +5 -0
- data/lib/pact_broker/ui/view_models/relationship.rb +38 -0
- data/lib/pact_broker/ui/views/relationships/show.haml +9 -0
- data/lib/pact_broker/verifications/repository.rb +45 -0
- data/lib/pact_broker/verifications/service.rb +40 -0
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/parse_semantic_version.rb +9 -6
- data/lib/pact_broker/webhooks/service.rb +8 -9
- data/lib/pact_broker/webhooks/webhook.rb +1 -1
- data/pact_broker.gemspec +3 -4
- data/pact_broker_client-pact_broker.json +4 -4
- data/script/publish.sh +2 -2
- data/script/record_verification.sh +3 -0
- data/spec/features/delete_pact_spec.rb +1 -1
- data/spec/features/get_verifications_for_consumer_version_spec.rb +33 -0
- data/spec/features/publish_verification_spec.rb +28 -0
- data/spec/fixtures/a_consumer-a_provider-2.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-3.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-conflict.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-merged.json +2 -2
- data/spec/fixtures/a_consumer-a_provider.json +1 -1
- data/spec/fixtures/consumer-provider.json +1 -1
- data/spec/fixtures/renderer_pact.json +1 -1
- data/spec/fixtures/verification.json +4 -0
- data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +91 -0
- data/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +0 -18
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +6 -2
- data/spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb +0 -3
- data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +61 -0
- data/spec/lib/pact_broker/api/decorators/verifications_decorator_spec.rb +42 -0
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +4 -0
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/latest_verifications_for_consumer_version_spec.rb +68 -0
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/pacticipants_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +92 -0
- data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +1 -1
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +10 -30
- data/spec/lib/pact_broker/domain/verification_spec.rb +41 -0
- data/spec/lib/pact_broker/domain/version_spec.rb +26 -0
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +1 -3
- data/spec/lib/pact_broker/pacticipants/repository_spec.rb +0 -16
- data/spec/lib/pact_broker/pacticipants/service_spec.rb +4 -3
- data/spec/lib/pact_broker/pacts/pact_params_spec.rb +14 -1
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +50 -0
- data/spec/lib/pact_broker/pacts/repository_spec.rb +85 -36
- data/spec/lib/pact_broker/ui/view_models/relationship_spec.rb +48 -2
- data/spec/lib/pact_broker/verifications/repository_spec.rb +92 -0
- data/spec/lib/pact_broker/verifications/service_spec.rb +61 -0
- data/spec/lib/pact_broker/versions/parse_semantic_version_spec.rb +39 -0
- data/spec/lib/pact_broker/webhooks/service_spec.rb +3 -40
- data/spec/migrations/23_pact_versions_spec.rb +95 -0
- data/spec/migrations/24_populate_pact_contents_spec.rb +48 -0
- data/spec/migrations/34_latest_tagged_pacts_spec.rb +108 -0
- data/spec/migrations/34_pact_revisions_spec.rb +106 -0
- data/spec/support/database_cleaner.rb +8 -4
- data/spec/support/provider_state_builder.rb +22 -8
- metadata +81 -36
- data/lib/pact_broker/pacts/database_model.rb +0 -35
- data/lib/pact_broker/pacts/latest_tagged_pacts.rb +0 -11
- data/lib/pact_broker/pacts/pact_version_content.rb +0 -11
- data/lib/pact_broker/webhooks/job.rb +0 -46
- data/script/foo-bar.json +0 -22
- data/script/publish-new.sh +0 -7
- data/script/recreate-pg-db.sh +0 -7
- data/spec/lib/pact_broker/webhooks/job_spec.rb +0 -67
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'pact_broker/domain/pact'
|
2
|
-
require 'pact_broker/pacts/pact_version_content'
|
3
|
-
|
4
|
-
module PactBroker
|
5
|
-
module Pacts
|
6
|
-
|
7
|
-
class DatabaseModel < Sequel::Model(:pacts)
|
8
|
-
|
9
|
-
set_primary_key :id
|
10
|
-
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id)
|
11
|
-
associate(:many_to_one, :consumer_version, :class => "PactBroker::Domain::Version", :key => :version_id, :primary_key => :id)
|
12
|
-
associate(:many_to_one, :pact_version_content, :key => :pact_version_content_sha, :primary_key => :sha)
|
13
|
-
|
14
|
-
DatabaseModel.plugin :timestamps, :update_on_create=>true
|
15
|
-
|
16
|
-
def to_domain
|
17
|
-
PactBroker::Domain::Pact.new(
|
18
|
-
id: id,
|
19
|
-
provider: provider,
|
20
|
-
consumer: consumer_version.pacticipant,
|
21
|
-
consumer_version_number: consumer_version.number,
|
22
|
-
consumer_version: to_version_domain,
|
23
|
-
json_content: pact_version_content.content,
|
24
|
-
updated_at: updated_at,
|
25
|
-
created_at: created_at
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_version_domain
|
30
|
-
OpenStruct.new(number: consumer_version.number, pacticipant: consumer_version.pacticipant, tags: consumer_version.tags, order: consumer_version.order)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'sucker_punch'
|
2
|
-
require 'pact_broker/webhooks/service'
|
3
|
-
require 'pact_broker/logging'
|
4
|
-
|
5
|
-
module PactBroker
|
6
|
-
module Webhooks
|
7
|
-
class Job
|
8
|
-
|
9
|
-
BACKOFF_TIMES = [10, 60, 120, 300, 600, 1200] #10 sec, 1 min, 2 min, 5 min, 10 min, 20 min => 38 minutes
|
10
|
-
|
11
|
-
include SuckerPunch::Job
|
12
|
-
include PactBroker::Logging
|
13
|
-
|
14
|
-
def perform data
|
15
|
-
@webhook = data[:webhook]
|
16
|
-
@error_count = data[:error_count] || 0
|
17
|
-
begin
|
18
|
-
webhook_execution_result = PactBroker::Webhooks::Service.execute_webhook_now webhook
|
19
|
-
reschedule_job unless webhook_execution_result.success?
|
20
|
-
rescue StandardError => e
|
21
|
-
handle_error e
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :webhook, :error_count
|
28
|
-
|
29
|
-
def handle_error e
|
30
|
-
log_error e
|
31
|
-
reschedule_job
|
32
|
-
end
|
33
|
-
|
34
|
-
def reschedule_job
|
35
|
-
case error_count
|
36
|
-
when 0...BACKOFF_TIMES.size
|
37
|
-
logger.debug "Re-enqeuing job for webhook #{webhook.uuid} to run in #{BACKOFF_TIMES[error_count]} seconds"
|
38
|
-
Job.perform_in(BACKOFF_TIMES[error_count], {webhook: webhook, error_count: error_count+1})
|
39
|
-
else
|
40
|
-
logger.error "Failed to execute webhook #{webhook.uuid} after #{BACKOFF_TIMES.size} times."
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/script/foo-bar.json
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"consumer": {
|
3
|
-
"name": "Foo"
|
4
|
-
},
|
5
|
-
"provider": {
|
6
|
-
"name": "Bar"
|
7
|
-
},
|
8
|
-
"interactions": [
|
9
|
-
{
|
10
|
-
"description" : "a request for something",
|
11
|
-
"providerState": null,
|
12
|
-
"request": {
|
13
|
-
"method": "get",
|
14
|
-
"path" : "/something"
|
15
|
-
},
|
16
|
-
"response": {
|
17
|
-
"status": 200,
|
18
|
-
"body" : "something"
|
19
|
-
}
|
20
|
-
}
|
21
|
-
]
|
22
|
-
}
|
data/script/publish-new.sh
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
# set -x
|
2
|
-
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
|
-
echo ${BODY} >> tmp.json
|
4
|
-
curl -v -XPUT \-H "Content-Type: application/json" \
|
5
|
-
-d@tmp.json \
|
6
|
-
http://127.0.0.1:9292/pacts/provider/Bar/consumer/Foo/version/1.0.0
|
7
|
-
rm tmp.json
|
data/script/recreate-pg-db.sh
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
psql postgres -c "drop database pact_broker;"
|
2
|
-
psql postgres -c "create database pact_broker;"
|
3
|
-
psql postgres -c "GRANT ALL PRIVILEGES ON DATABASE pact_broker to pact_broker;"
|
4
|
-
ip=$(ifconfig en0 | sed -n -e '/inet/s/.*inet \([0-9.]*\) netmask .*/\1/p')
|
5
|
-
echo ""
|
6
|
-
echo "run the following command to set your environment variables:"
|
7
|
-
echo "export PACT_BROKER_DATABASE_HOST=${ip}"
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'pact_broker/webhooks/job'
|
2
|
-
|
3
|
-
module PactBroker
|
4
|
-
module Webhooks
|
5
|
-
describe Job do
|
6
|
-
|
7
|
-
before do
|
8
|
-
allow(PactBroker::Webhooks::Service).to receive(:execute_webhook_now)
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:webhook) { double("webhook", uuid: '1234') }
|
12
|
-
|
13
|
-
context "when an error occurs for the first time" do
|
14
|
-
before do
|
15
|
-
allow(PactBroker::Webhooks::Service).to receive(:execute_webhook_now).and_raise("an error")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "reschedules the job in 10 seconds" do
|
19
|
-
expect(Job).to receive(:perform_in).with(10, {webhook: webhook, error_count: 1})
|
20
|
-
Job.new.perform(webhook: webhook)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when the webhook execution result is not successful for the first time" do
|
25
|
-
before do
|
26
|
-
allow(PactBroker::Webhooks::Service).to receive(:execute_webhook_now).and_return(instance_double("PactBroker::Domain::WebhookExecutionResult", success?: false))
|
27
|
-
end
|
28
|
-
|
29
|
-
it "reschedules the job in 10 seconds" do
|
30
|
-
expect(Job).to receive(:perform_in).with(10, {webhook: webhook, error_count: 1})
|
31
|
-
Job.new.perform(webhook: webhook)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when an error occurs for the second time" do
|
36
|
-
before do
|
37
|
-
allow(PactBroker::Webhooks::Service).to receive(:execute_webhook_now).and_raise("an error")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "reschedules the job in 60 seconds" do
|
41
|
-
expect(Job).to receive(:perform_in).with(60, {webhook: webhook, error_count: 2 })
|
42
|
-
Job.new.perform(webhook: webhook, error_count: 1)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when an error occurs for the last time" do
|
47
|
-
before do
|
48
|
-
allow(PactBroker::Webhooks::Service).to receive(:execute_webhook_now).and_raise("an error")
|
49
|
-
end
|
50
|
-
|
51
|
-
subject { Job.new.perform(webhook: webhook, error_count: 6) }
|
52
|
-
|
53
|
-
it "does not reschedule the job" do
|
54
|
-
expect(Job).to_not receive(:perform_in)
|
55
|
-
subject
|
56
|
-
end
|
57
|
-
|
58
|
-
it "logs that it has failed" do
|
59
|
-
allow(Job.logger).to receive(:error)
|
60
|
-
expect(Job.logger).to receive(:error).with(/Failed to execute/)
|
61
|
-
subject
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|