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
@@ -8,9 +8,11 @@ module PactBroker
|
|
8
8
|
|
9
9
|
let(:consumer) { instance_double("PactBroker::Domain::Pacticipant", name: 'Consumer Name')}
|
10
10
|
let(:provider) { instance_double("PactBroker::Domain::Pacticipant", name: 'Provider Name')}
|
11
|
-
let(:
|
11
|
+
let(:latest_pact) { instance_double("PactBroker::Domain::Pact") }
|
12
|
+
let(:latest_verification) { instance_double("PactBroker::Domain::Verification") }
|
13
|
+
let(:domain_relationship) { PactBroker::Domain::Relationship.new(consumer, provider, latest_pact, latest_verification)}
|
12
14
|
|
13
|
-
subject { Relationship.new(
|
15
|
+
subject { Relationship.new(domain_relationship) }
|
14
16
|
|
15
17
|
its(:consumer_name) { should eq 'Consumer Name'}
|
16
18
|
its(:provider_name) { should eq 'Provider Name'}
|
@@ -18,6 +20,50 @@ module PactBroker
|
|
18
20
|
its(:consumer_group_url) { should eq "/groups/Consumer%20Name" }
|
19
21
|
its(:provider_group_url) { should eq "/groups/Provider%20Name" }
|
20
22
|
|
23
|
+
describe "verification_status" do
|
24
|
+
let(:domain_relationship) do
|
25
|
+
instance_double("PactBroker::Domain::Relationship",
|
26
|
+
ever_verified?: ever_verified,
|
27
|
+
pact_changed_since_last_verification?: pact_changed,
|
28
|
+
latest_verification_successful?: success,
|
29
|
+
provider_name: "Foo",
|
30
|
+
latest_verification_provider_version: "4.5.6")
|
31
|
+
end
|
32
|
+
let(:ever_verified) { true }
|
33
|
+
let(:pact_changed) { false }
|
34
|
+
let(:success) { true }
|
35
|
+
|
36
|
+
subject { Relationship.new(domain_relationship) }
|
37
|
+
|
38
|
+
context "when the pact has never been verified" do
|
39
|
+
let(:ever_verified) { false }
|
40
|
+
its(:verification_status) { is_expected.to eq "" }
|
41
|
+
its(:warning?) { is_expected.to be false }
|
42
|
+
its(:verification_tooltip) { is_expected.to eq nil }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when the pact has changed since the last successful verification" do
|
46
|
+
let(:pact_changed) { true }
|
47
|
+
its(:verification_status) { is_expected.to eq "warning" }
|
48
|
+
its(:warning?) { is_expected.to be true }
|
49
|
+
its(:verification_tooltip) { is_expected.to eq "Pact has changed since last successful verification by Foo (v4.5.6)" }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the pact has not changed since the last successful verification" do
|
53
|
+
let(:pact_changed) { false }
|
54
|
+
its(:verification_status) { is_expected.to eq "success" }
|
55
|
+
its(:warning?) { is_expected.to be false }
|
56
|
+
its(:verification_tooltip) { is_expected.to eq "Successfully verified by Foo (v4.5.6)" }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the pact verification failed" do
|
60
|
+
let(:success) { false }
|
61
|
+
its(:verification_status) { is_expected.to eq "danger" }
|
62
|
+
its(:warning?) { is_expected.to be false }
|
63
|
+
its(:verification_tooltip) { is_expected.to eq "Verification by Foo (v4.5.6) failed" }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
21
67
|
describe "<=>" do
|
22
68
|
|
23
69
|
let(:relationship_model_4) { double("PactBroker::Domain::Relationship", consumer_name: "A", provider_name: "X") }
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'pact_broker/verifications/repository'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Verifications
|
5
|
+
describe Repository do
|
6
|
+
|
7
|
+
describe "#verification_count_for_pact" do
|
8
|
+
let!(:pact_1) do
|
9
|
+
ProviderStateBuilder.new
|
10
|
+
.create_consumer("Consumer")
|
11
|
+
.create_provider("Provider")
|
12
|
+
.create_consumer_version("1.2.3")
|
13
|
+
.create_pact
|
14
|
+
.create_verification(number: 1)
|
15
|
+
.create_verification(number: 2)
|
16
|
+
.and_return(:pact)
|
17
|
+
end
|
18
|
+
let!(:pact_2) do
|
19
|
+
ProviderStateBuilder.new
|
20
|
+
.create_consumer("Foo")
|
21
|
+
.create_provider("Bar")
|
22
|
+
.create_consumer_version("4.5.6")
|
23
|
+
.create_pact
|
24
|
+
.create_verification(number: 1)
|
25
|
+
.and_return(:pact)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns the number of verifications for the given pact" do
|
29
|
+
expect(Repository.new.verification_count_for_pact(pact_1)).to eq 2
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#find_latest_verifications_for_consumer_version" do
|
34
|
+
before do
|
35
|
+
ProviderStateBuilder.new
|
36
|
+
.create_provider("Provider1")
|
37
|
+
.create_consumer("Consumer1")
|
38
|
+
.create_consumer_version("1.0.0")
|
39
|
+
.create_pact
|
40
|
+
.create_verification(number: 1)
|
41
|
+
.create_consumer_version("1.2.3")
|
42
|
+
.create_pact
|
43
|
+
.create_verification(number: 1)
|
44
|
+
.create_verification(number: 2, provider_version: "7.8.9")
|
45
|
+
.create_provider("Provider2")
|
46
|
+
.create_pact
|
47
|
+
.create_verification(number: 1, provider_version: "6.5.4")
|
48
|
+
|
49
|
+
ProviderStateBuilder.new
|
50
|
+
.create_provider("Provider3")
|
51
|
+
.create_consumer("Consumer2")
|
52
|
+
.create_consumer_version("1.2.3")
|
53
|
+
.create_pact
|
54
|
+
.create_verification(number: 1)
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:latest_verifications) { Repository.new.find_latest_verifications_for_consumer_version("Consumer1", "1.2.3")}
|
58
|
+
|
59
|
+
it "finds the latest verifications for the given consumer version" do
|
60
|
+
expect(latest_verifications.first.provider_version).to eq "7.8.9"
|
61
|
+
expect(latest_verifications.last.provider_version).to eq "6.5.4"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#find_latest_verification_for" do
|
66
|
+
before do
|
67
|
+
ProviderStateBuilder.new
|
68
|
+
.create_provider("Provider1")
|
69
|
+
.create_consumer("Consumer1")
|
70
|
+
.create_consumer_version("1.2.3")
|
71
|
+
.create_pact
|
72
|
+
.create_verification(number: 1, provider_version: "2.3.4")
|
73
|
+
.create_verification(number: 2, provider_version: "7.8.9")
|
74
|
+
.create_consumer_version("1.0.0")
|
75
|
+
.create_pact
|
76
|
+
.create_verification(number: 1, provider_version: "5.4.3")
|
77
|
+
.create_provider("Provider2")
|
78
|
+
.create_pact
|
79
|
+
.create_verification(number: 1, provider_version: "6.5.4")
|
80
|
+
.create_consumer_version("2.0.0")
|
81
|
+
.create_pact
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:latest_verification) { Repository.new.find_latest_verification_for("Consumer1", "Provider1")}
|
85
|
+
|
86
|
+
it "finds the latest verifications for the given consumer version" do
|
87
|
+
expect(latest_verification.provider_version).to eq "7.8.9"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pact_broker/verifications/service'
|
2
|
+
require 'pact_broker/verifications/repository'
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
|
6
|
+
module Verifications
|
7
|
+
describe Service do
|
8
|
+
|
9
|
+
subject { PactBroker::Verifications::Service }
|
10
|
+
|
11
|
+
describe "#next_number_for" do
|
12
|
+
|
13
|
+
let(:pact) { double(:pact) }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow_any_instance_of(PactBroker::Verifications::Repository).to receive(:verification_count_for_pact).and_return(2)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the number for the next build to be recorded for a pact" do
|
20
|
+
expect(subject.next_number_for(pact)).to eq 3
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#create" do
|
25
|
+
let(:params) { {'success' => true, 'providerApplicationVersion' => '4.5.6'} }
|
26
|
+
let(:pact) { ProviderStateBuilder.new.create_pact_with_hierarchy }
|
27
|
+
let(:create_verification) { subject.create 3, params, pact }
|
28
|
+
|
29
|
+
it "logs the creation" do
|
30
|
+
allow(PactBroker.logger).to receive(:info).and_call_original
|
31
|
+
expect(PactBroker.logger).to receive(:info).with(/.*verification.*3.*success/)
|
32
|
+
create_verification
|
33
|
+
end
|
34
|
+
|
35
|
+
it "sets the verification attributes" do
|
36
|
+
verification = create_verification
|
37
|
+
expect(verification.success).to be true
|
38
|
+
expect(verification.number).to eq 3
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets the pact content for the verification" do
|
42
|
+
verification = create_verification
|
43
|
+
expect(verification.pact_version_id).to_not be_nil
|
44
|
+
expect(verification.pact_version.id).to eq pact.id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#errors" do
|
49
|
+
let(:params) { {} }
|
50
|
+
|
51
|
+
it "returns errors" do
|
52
|
+
expect(subject.errors(params)).to_not be_empty
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns something that responds to :messages" do
|
56
|
+
expect(subject.errors(params).messages).to_not be_empty
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact_broker/versions/parse_semantic_version'
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Versions
|
6
|
+
describe ParseSemanticVersion do
|
7
|
+
|
8
|
+
describe ".call" do
|
9
|
+
context "when parsing a semantic version" do
|
10
|
+
|
11
|
+
subject { ParseSemanticVersion.call("1.2.3") }
|
12
|
+
|
13
|
+
it "returns the version" do
|
14
|
+
expect(subject.major).to eq 1
|
15
|
+
expect(subject.minor).to eq 2
|
16
|
+
expect(subject.to_s).to eq "1.2.3"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns a comparable version" do
|
20
|
+
expect(subject).to be > ParseSemanticVersion.call("1.2.2")
|
21
|
+
expect(subject).to be == ParseSemanticVersion.call("1.2.3")
|
22
|
+
expect(subject).to be < ParseSemanticVersion.call("1.3.1")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns nil when version is invalid" do
|
26
|
+
expect(ParseSemanticVersion.call("abc")).to be_nil
|
27
|
+
expect(ParseSemanticVersion.call("1")).to be_nil
|
28
|
+
expect(ParseSemanticVersion.call("1.2")).to be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "accepts semver metadata" do
|
32
|
+
expect(ParseSemanticVersion.call("1.2.3+abc.234")).not_to be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'pact_broker/webhooks/service'
|
3
|
-
require 'webmock/rspec'
|
4
|
-
require 'sucker_punch/testing/inline'
|
5
3
|
|
6
4
|
module PactBroker
|
7
5
|
|
@@ -14,11 +12,11 @@ module PactBroker
|
|
14
12
|
let(:consumer_version) { PactBroker::Domain::Version.new(number: '1.2.3') }
|
15
13
|
let(:consumer) { PactBroker::Domain::Pacticipant.new(name: 'Consumer') }
|
16
14
|
let(:provider) { PactBroker::Domain::Pacticipant.new(name: 'Provider') }
|
17
|
-
let(:webhooks) { [instance_double(PactBroker::Domain::Webhook
|
15
|
+
let(:webhooks) { [instance_double(PactBroker::Domain::Webhook)]}
|
18
16
|
|
19
17
|
before do
|
20
18
|
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:find_by_consumer_and_provider).and_return(webhooks)
|
21
|
-
allow(
|
19
|
+
allow(Service).to receive(:run_later)
|
22
20
|
end
|
23
21
|
|
24
22
|
subject { Service.execute_webhooks pact }
|
@@ -47,42 +45,7 @@ module PactBroker
|
|
47
45
|
subject
|
48
46
|
end
|
49
47
|
end
|
50
|
-
|
51
|
-
context "when there is a scheduling error" do
|
52
|
-
before do
|
53
|
-
allow(Job).to receive(:perform_async).and_raise("an error")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "logs the error" do
|
57
|
-
allow(Service.logger).to receive(:error)
|
58
|
-
expect(Service.logger).to receive(:error).with(/an error/)
|
59
|
-
subject
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe ".execute_webhooks integration test" do
|
65
|
-
let!(:http_request) do
|
66
|
-
stub_request(:get, "http://example.org").
|
67
|
-
to_return(:status => 200)
|
68
|
-
end
|
69
|
-
|
70
|
-
let(:pact) do
|
71
|
-
ProviderStateBuilder.new
|
72
|
-
.create_consumer
|
73
|
-
.create_provider
|
74
|
-
.create_consumer_version
|
75
|
-
.create_pact
|
76
|
-
.create_webhook(method: 'GET', url: 'http://example.org')
|
77
|
-
.and_return(:pact)
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
it "executes the HTTP request of the webhook" do
|
82
|
-
PactBroker::Webhooks::Service.execute_webhooks pact
|
83
|
-
expect(http_request).to have_been_made
|
84
|
-
end
|
85
48
|
end
|
86
49
|
end
|
87
50
|
end
|
88
|
-
end
|
51
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'tasks/database'
|
2
|
+
|
3
|
+
describe 'migrate to pact versions (migrate 22-31)', no_db_clean: :true do
|
4
|
+
|
5
|
+
def create table_name, params, id_column_name = :id
|
6
|
+
database[table_name].insert(params);
|
7
|
+
database[table_name].order(id_column_name).last
|
8
|
+
end
|
9
|
+
|
10
|
+
def clean table_name
|
11
|
+
database[table_name].delete rescue puts "Error cleaning #{table_name} #{$!}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_connection
|
15
|
+
Sequel::DATABASES.clear
|
16
|
+
DB.connection_for_env 'test'
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:database) { new_connection }
|
20
|
+
|
21
|
+
before do
|
22
|
+
PactBroker::Database.delete_database_file
|
23
|
+
PactBroker::Database.ensure_database_dir_exists
|
24
|
+
database = new_connection
|
25
|
+
PactBroker::Database.migrate(22)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:now) { DateTime.new(2017, 1, 1) }
|
29
|
+
let(:pact_updated_at) { DateTime.new(2017, 1, 2) }
|
30
|
+
let!(:consumer) { create(:pacticipants, {name: 'Consumer', created_at: now, updated_at: now}) }
|
31
|
+
let!(:provider) { create(:pacticipants, {name: 'Provider', created_at: now, updated_at: now}) }
|
32
|
+
let!(:consumer_version_1) { create(:versions, {number: '1.2.3', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
33
|
+
let!(:consumer_version_2) { create(:versions, {number: '4.5.6', order: 2, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
34
|
+
let!(:pact_version_content) { create(:pact_version_contents, {content: {some: 'json'}.to_json, sha: '1234', created_at: now, updated_at: now}, :sha) }
|
35
|
+
let!(:pact_1) { create(:pacts, {version_id: consumer_version_1[:id], provider_id: provider[:id], pact_version_content_sha: '1234', created_at: now, updated_at: pact_updated_at}) }
|
36
|
+
let!(:pact_2) { create(:pacts, {version_id: consumer_version_2[:id], provider_id: provider[:id], pact_version_content_sha: '1234', created_at: now, updated_at: pact_updated_at}) }
|
37
|
+
|
38
|
+
|
39
|
+
let(:do_migration) do
|
40
|
+
PactBroker::Database.migrate(34)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "keeps the same number of pacts" do
|
44
|
+
do_migration
|
45
|
+
expect(database[:latest_pact_publications_by_consumer_versions].count).to eq 2
|
46
|
+
end
|
47
|
+
|
48
|
+
it "uses the old updated date for the new creation date" do
|
49
|
+
do_migration
|
50
|
+
# expect(new_connection[:latest_pact_publications_by_consumer_versions].order(:id).first[:created_at]).to eq pact_updated_at
|
51
|
+
expect(database[:latest_pact_publications_by_consumer_versions].order(:id).first[:created_at]).to eq pact_updated_at
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sets each revision number to 1" do
|
55
|
+
do_migration
|
56
|
+
expect(database[:latest_pact_publications_by_consumer_versions].order(:id).first[:revision_number]).to eq 1
|
57
|
+
expect(database[:latest_pact_publications_by_consumer_versions].order(:id).last[:revision_number]).to eq 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it "migrates the values correctly for the first pact" do
|
61
|
+
|
62
|
+
old_all_pact = database[:all_pacts].order(:id).first
|
63
|
+
old_all_pact.delete(:updated_at)
|
64
|
+
old_all_pact.delete(:created_at)
|
65
|
+
old_all_pact.delete(:created_at)
|
66
|
+
old_all_pact[:pact_version_sha] = old_all_pact.delete(:pact_version_content_sha)
|
67
|
+
do_migration
|
68
|
+
database[:latest_pact_publications_by_consumer_versions]
|
69
|
+
new_all_pact = database[:latest_pact_publications_by_consumer_versions].order(:id).first
|
70
|
+
new_all_pact.delete(:created_at)
|
71
|
+
new_all_pact.delete(:revision_number)
|
72
|
+
new_all_pact.delete(:pact_version_id)
|
73
|
+
expect(new_all_pact).to eq old_all_pact
|
74
|
+
end
|
75
|
+
|
76
|
+
it "migrates the values correctly for the second pact" do
|
77
|
+
old_all_pact = database[:all_pacts].order(:id).last
|
78
|
+
old_all_pact.delete(:updated_at)
|
79
|
+
old_all_pact.delete(:created_at)
|
80
|
+
old_all_pact[:pact_version_sha] = old_all_pact.delete(:pact_version_content_sha)
|
81
|
+
do_migration
|
82
|
+
new_all_pact = database[:latest_pact_publications_by_consumer_versions].order(:id).last
|
83
|
+
new_all_pact.delete(:created_at)
|
84
|
+
new_all_pact.delete(:revision_number)
|
85
|
+
new_all_pact.delete(:pact_version_id)
|
86
|
+
expect(new_all_pact).to eq old_all_pact
|
87
|
+
end
|
88
|
+
|
89
|
+
after do
|
90
|
+
PactBroker::Database.delete_database_file
|
91
|
+
PactBroker::Database.ensure_database_dir_exists
|
92
|
+
database = new_connection
|
93
|
+
PactBroker::Database.migrate
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'tasks/database'
|
2
|
+
|
3
|
+
describe 'migrate to pact versions (migrate 22-24)', no_db_clean: :true do
|
4
|
+
|
5
|
+
def create table_name, params, id_column_name = :id
|
6
|
+
database[table_name].insert(params);
|
7
|
+
database[table_name].order(id_column_name).last
|
8
|
+
end
|
9
|
+
|
10
|
+
def new_connection
|
11
|
+
DB.connection_for_env 'test'
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:database) { new_connection }
|
15
|
+
|
16
|
+
before do
|
17
|
+
PactBroker::Database.delete_database_file
|
18
|
+
PactBroker::Database.ensure_database_dir_exists
|
19
|
+
database = new_connection
|
20
|
+
PactBroker::Database.migrate(22)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:now) { DateTime.new(2017, 1, 1) }
|
24
|
+
let(:pact_updated_at) { DateTime.new(2017, 1, 2) }
|
25
|
+
let!(:consumer) { create(:pacticipants, {name: 'Consumer', created_at: now, updated_at: now}) }
|
26
|
+
let!(:provider) { create(:pacticipants, {name: 'Provider', created_at: now, updated_at: now}) }
|
27
|
+
let!(:consumer_version) { create(:versions, {number: '1.2.3', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
28
|
+
let!(:pact_version_content) { create(:pact_version_contents, {content: {some: 'json'}.to_json, sha: '1234', created_at: now, updated_at: now}, :sha) }
|
29
|
+
let!(:pact_1) { create(:pacts, {version_id: consumer_version[:id], provider_id: provider[:id], pact_version_content_sha: '1234', created_at: now, updated_at: pact_updated_at}) }
|
30
|
+
|
31
|
+
let!(:pact_version_content_orphan) { create(:pact_version_contents, {content: {some: 'json'}.to_json, sha: '4567', created_at: now, updated_at: now}, :sha) }
|
32
|
+
|
33
|
+
let(:do_migration) do
|
34
|
+
PactBroker::Database.migrate(34)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "deletes orphan pact_versions" do
|
38
|
+
do_migration
|
39
|
+
expect(database[:pact_versions].count).to eq 1
|
40
|
+
end
|
41
|
+
|
42
|
+
after do
|
43
|
+
PactBroker::Database.delete_database_file
|
44
|
+
PactBroker::Database.ensure_database_dir_exists
|
45
|
+
database = new_connection
|
46
|
+
PactBroker::Database.migrate
|
47
|
+
end
|
48
|
+
end
|