pact_broker 2.82.0 → 2.85.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +53 -0
- data/Dockerfile +1 -1
- data/db/migrations/20210815_add_provider_version_id_index_to_verifications.rb +7 -0
- data/db/migrations/20210816_create_branches_tables.rb +40 -0
- data/db/migrations/20210818_add_consumer_version_selectors_to_verification.rb +8 -0
- data/db/migrations/20210831_add_index_to_pact_publications.rb +7 -0
- data/db/migrations/20210908_add_auto_created.rb +24 -0
- data/db/migrations/20210913_add_pending_to_verifications.rb +7 -0
- data/issue-reproduction/Dockerfile-pact-broker +1 -1
- data/lib/pact/doc/markdown/consumer_contract_renderer.rb +3 -3
- data/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema.rb → pacts_for_verification_json_query_schema.rb} +1 -1
- data/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema.rb → pacts_for_verification_query_string_schema.rb} +1 -1
- data/lib/pact_broker/api/decorators/branch_version_decorator.rb +20 -0
- data/lib/pact_broker/api/decorators/dashboard_decorator.rb +4 -2
- data/lib/pact_broker/api/decorators/embedded_branch_version_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/embedded_tag_decorator.rb +0 -5
- data/lib/pact_broker/api/decorators/matrix_decorator.rb +11 -2
- data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +8 -0
- data/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator.rb → pacts_for_verification_query_decorator.rb} +2 -2
- data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -2
- data/lib/pact_broker/api/decorators/verification_summary_decorator.rb +1 -2
- data/lib/pact_broker/api/decorators/version_decorator.rb +1 -1
- data/lib/pact_broker/api/middleware/configuration.rb +33 -0
- data/lib/pact_broker/api/pact_broker_urls.rb +13 -1
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +15 -11
- data/lib/pact_broker/api/resources/branch_version.rb +48 -0
- data/lib/pact_broker/api/resources/index.rb +6 -0
- data/lib/pact_broker/api/resources/pact_versions_for_branch.rb +40 -0
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +6 -6
- data/lib/pact_broker/api/resources/verifications.rb +7 -2
- data/lib/pact_broker/api/resources/version.rb +0 -8
- data/lib/pact_broker/api.rb +2 -0
- data/lib/pact_broker/app.rb +2 -0
- data/lib/pact_broker/badges/service.rb +3 -1
- data/lib/pact_broker/config/runtime_configuration.rb +12 -0
- data/lib/pact_broker/configuration.rb +33 -29
- data/lib/pact_broker/contracts/service.rb +1 -1
- data/lib/pact_broker/db/clean/selector.rb +54 -0
- data/lib/pact_broker/db/clean.rb +7 -1
- data/lib/pact_broker/db/clean_incremental.rb +13 -5
- data/lib/pact_broker/db/data_migrations/create_branches.rb +97 -0
- data/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb +2 -0
- data/lib/pact_broker/db/migrate_data.rb +1 -1
- data/lib/pact_broker/db/models.rb +6 -0
- data/lib/pact_broker/deployments/deployed_version.rb +4 -0
- data/lib/pact_broker/deployments/deployed_version_service.rb +4 -3
- data/lib/pact_broker/deployments/environment.rb +4 -0
- data/lib/pact_broker/deployments/environment_service.rb +13 -8
- data/lib/pact_broker/diagnostic/resources/base_resource.rb +4 -0
- data/lib/pact_broker/diagnostic/resources/dependencies.rb +1 -1
- data/lib/pact_broker/diagnostic/resources/heartbeat.rb +2 -3
- data/lib/pact_broker/doc/views/index/pacticipant-branch-version.markdown +14 -0
- data/lib/pact_broker/doc/views/webhooks.markdown +1 -0
- data/lib/pact_broker/domain/index_item.rb +15 -17
- data/lib/pact_broker/domain/pacticipant.rb +11 -0
- data/lib/pact_broker/domain/tag.rb +1 -2
- data/lib/pact_broker/domain/verification.rb +29 -14
- data/lib/pact_broker/domain/version.rb +112 -29
- data/lib/pact_broker/domain/webhook.rb +22 -10
- data/lib/pact_broker/domain/webhook_request.rb +2 -2
- data/lib/pact_broker/index/service.rb +83 -28
- data/lib/pact_broker/locale/en.yml +4 -0
- data/lib/pact_broker/matrix/quick_row.rb +6 -6
- data/lib/pact_broker/matrix/service.rb +4 -0
- data/lib/pact_broker/matrix/unresolved_selector.rb +3 -2
- data/lib/pact_broker/metrics/service.rb +7 -1
- data/lib/pact_broker/pacts/metadata.rb +7 -2
- data/lib/pact_broker/pacts/pact_publication.rb +59 -25
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +113 -33
- data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +18 -13
- data/lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb +16 -4
- data/lib/pact_broker/pacts/pact_version.rb +13 -1
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +4 -10
- data/lib/pact_broker/pacts/repository.rb +6 -1
- data/lib/pact_broker/pacts/selected_pact.rb +20 -0
- data/lib/pact_broker/pacts/selector.rb +98 -33
- data/lib/pact_broker/pacts/service.rb +21 -0
- data/lib/pact_broker/repositories.rb +5 -0
- data/lib/pact_broker/services.rb +9 -0
- data/lib/pact_broker/test/http_test_data_builder.rb +35 -9
- data/lib/pact_broker/test/test_data_builder.rb +32 -26
- data/lib/pact_broker/ui/app.rb +7 -1
- data/lib/pact_broker/ui/controllers/dashboard.rb +80 -0
- data/lib/pact_broker/ui/controllers/groups.rb +23 -8
- data/lib/pact_broker/ui/helpers/url_helper.rb +5 -1
- data/lib/pact_broker/ui/view_models/index_item.rb +56 -3
- data/lib/pact_broker/ui/view_models/matrix_branch.rb +39 -0
- data/lib/pact_broker/ui/view_models/matrix_line.rb +11 -16
- data/lib/pact_broker/ui/view_models/matrix_tag.rb +0 -1
- data/lib/pact_broker/ui/views/dashboard/show.haml +195 -0
- data/lib/pact_broker/ui/views/groups/show.html.erb +60 -14
- data/lib/pact_broker/ui/views/index/_dashboard_navbar.haml +7 -0
- data/lib/pact_broker/ui/views/index/_navbar.haml +0 -7
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +14 -11
- data/lib/pact_broker/ui/views/index/show.haml +35 -13
- data/lib/pact_broker/ui/views/matrix/show.haml +15 -11
- data/lib/pact_broker/verifications/pseudo_branch_status.rb +2 -0
- data/lib/pact_broker/verifications/repository.rb +6 -11
- data/lib/pact_broker/verifications/service.rb +11 -5
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/branch.rb +29 -0
- data/lib/pact_broker/versions/branch_head.rb +45 -0
- data/lib/pact_broker/versions/branch_service.rb +24 -0
- data/lib/pact_broker/versions/branch_version.rb +64 -0
- data/lib/pact_broker/versions/branch_version_repository.rb +34 -0
- data/lib/pact_broker/versions/eager_loaders.rb +0 -42
- data/lib/pact_broker/versions/repository.rb +25 -12
- data/lib/pact_broker/versions/service.rb +3 -22
- data/lib/pact_broker/webhooks/event_listener.rb +3 -3
- data/lib/pact_broker/webhooks/execution_configuration.rb +16 -0
- data/lib/pact_broker/webhooks/execution_configuration_creator.rb +3 -0
- data/lib/pact_broker/webhooks/job.rb +1 -1
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +20 -3
- data/lib/pact_broker/webhooks/trigger_service.rb +2 -2
- data/lib/pact_broker/webhooks/webhook_execution_result.rb +3 -7
- data/lib/pact_broker/webhooks/webhook_request_logger.rb +4 -12
- data/lib/pact_broker/webhooks/webhook_request_template.rb +6 -8
- data/lib/sequel/plugins/insert_ignore.rb +4 -0
- data/lib/sequel/plugins/upsert.rb +4 -0
- data/pact_broker.gemspec +4 -0
- data/public/javascripts/index.js +152 -50
- data/public/javascripts/pact.js +14 -14
- data/public/stylesheets/index.css +1 -2
- data/public/stylesheets/pact.css +11 -0
- data/scaffolding/templates/decorator.rb.erb +3 -1
- data/scaffolding/templates/migration.erb +1 -1
- data/scaffolding/templates/model.erb +2 -2
- data/scaffolding/templates/repository.rb.erb +2 -2
- data/scaffolding/templates/repository_spec.rb.erb +1 -1
- data/scaffolding/templates/resource.erb +2 -2
- data/scaffolding/templates/resource_spec.rb.erb +1 -1
- data/scaffolding/templates/service.rb.erb +3 -3
- data/scaffolding/templates/service_spec.rb.erb +1 -1
- data/script/data/auto-create-things-for-tags.rb +2 -0
- data/script/data/branches.rb +35 -0
- data/script/data/contract-published-requiring-verification.rb +1 -1
- data/script/data/environments.rb +0 -0
- data/script/data/issue-494.rb +25 -0
- data/script/data/pending.rb +26 -0
- data/script/data/tags.rb +35 -0
- data/script/data/webhook.rb +22 -0
- data/script/seed.rb +50 -89
- data/spec/features/create_branch_version_spec.rb +29 -0
- data/spec/features/create_tag_spec.rb +1 -1
- data/spec/features/create_version_spec.rb +2 -4
- data/spec/features/delete_pact_versions_for_branch_spec.rb +34 -0
- data/spec/features/get_branch_version_spec.rb +12 -0
- data/spec/features/publish_pact_all_in_one_spec.rb +0 -1
- data/spec/features/update_version_spec.rb +0 -55
- data/spec/fixtures/approvals/modifiable_resources.approved.json +7 -0
- data/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +1 -2
- data/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +1 -2
- data/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +1 -2
- data/spec/fixtures/dashboard.json +4 -2
- data/spec/integration/app_spec.rb +6 -6
- data/spec/integration/ui/index_spec.rb +0 -2
- data/spec/integration/ui/matrix_spec.rb +0 -1
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +2 -2
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_combinations_spec.rb → pacts_for_verification_json_query_schema_combinations_spec.rb} +6 -6
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_spec.rb → pacts_for_verification_json_query_schema_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema_spec.rb → pacts_for_verification_query_string_schema_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +7 -7
- data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +19 -4
- data/spec/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator_spec.rb → pacts_for_verification_query_decorator_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb +2 -2
- data/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +2 -0
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +7 -3
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +1 -1
- data/spec/lib/pact_broker/api/middleware/configuration_spec.rb +43 -0
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +6 -4
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +1 -1
- data/spec/lib/pact_broker/badges/service_spec.rb +22 -0
- data/spec/lib/pact_broker/contracts/service_spec.rb +24 -3
- data/spec/lib/pact_broker/db/clean_spec.rb +2 -2
- data/spec/lib/pact_broker/db/data_migrations/create_branches_spec.rb +57 -0
- data/spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb +4 -4
- data/spec/lib/pact_broker/diagnostic/resources/heartbeat_spec.rb +3 -4
- data/spec/lib/pact_broker/domain/index_item_spec.rb +1 -1
- data/spec/lib/pact_broker/domain/version_spec.rb +127 -36
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +2 -1
- data/spec/lib/pact_broker/domain/webhook_spec.rb +15 -5
- data/spec/lib/pact_broker/index/service_spec.rb +1 -5
- data/spec/lib/pact_broker/index/service_view_spec.rb +144 -0
- data/spec/lib/pact_broker/matrix/service_spec.rb +10 -1
- data/spec/lib/pact_broker/metrics/service_spec.rb +4 -1
- data/spec/lib/pact_broker/pacts/metadata_spec.rb +11 -3
- data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +109 -10
- data/spec/lib/pact_broker/pacts/pact_publication_latest_verification_spec.rb +29 -0
- data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +3 -2
- data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +5 -5
- data/spec/lib/pact_broker/pacts/repository_find_for_currently_deployed_spec.rb +2 -2
- data/spec/lib/pact_broker/pacts/repository_find_for_currently_supported_releases_spec.rb +2 -2
- data/spec/lib/pact_broker/pacts/repository_spec.rb +15 -2
- data/spec/lib/pact_broker/pacts/selector_spec.rb +45 -3
- data/spec/lib/pact_broker/pacts/service_spec.rb +61 -0
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +5 -5
- data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -5
- data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +21 -6
- data/spec/lib/pact_broker/verifications/pseudo_branch_status_spec.rb +9 -1
- data/spec/lib/pact_broker/verifications/repository_spec.rb +39 -30
- data/spec/lib/pact_broker/verifications/service_spec.rb +9 -5
- data/spec/lib/pact_broker/versions/branch_service_spec.rb +71 -0
- data/spec/lib/pact_broker/versions/branch_version_repository_spec.rb +81 -0
- data/spec/lib/pact_broker/versions/branch_version_spec.rb +27 -0
- data/spec/lib/pact_broker/versions/repository_spec.rb +91 -6
- data/spec/lib/pact_broker/versions/service_spec.rb +4 -3
- data/spec/lib/pact_broker/webhooks/job_spec.rb +4 -4
- data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -0
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +9 -5
- data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +6 -12
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +3 -2
- data/spec/lib/sequel/plugins/upsert_spec.rb +11 -5
- data/spec/migrations/44_add_provider_version_to_verification_spec.rb +6 -9
- data/spec/service_consumers/pact_helper.rb +2 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/generated_markdown.md +3 -3
- metadata +90 -17
- data/lib/pact_broker/versions/lazy_loaders.rb +0 -13
- data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +0 -56
@@ -1,14 +1,14 @@
|
|
1
|
-
require "pact_broker/api/decorators/
|
1
|
+
require "pact_broker/api/decorators/pacts_for_verification_query_decorator"
|
2
2
|
|
3
3
|
module PactBroker
|
4
4
|
module Api
|
5
5
|
module Decorators
|
6
|
-
describe
|
6
|
+
describe PactsForVerificationQueryDecorator do
|
7
7
|
|
8
8
|
let(:provider_version_tags) { %w[dev] }
|
9
9
|
let(:provider_version_branch) { "main" }
|
10
10
|
|
11
|
-
subject {
|
11
|
+
subject { PactsForVerificationQueryDecorator.new(OpenStruct.new).from_hash(params) }
|
12
12
|
|
13
13
|
context "when parsing JSON params" do
|
14
14
|
let(:params) do
|
@@ -80,13 +80,13 @@ module PactBroker
|
|
80
80
|
context "when the reason is NoEnvironmentSpecified" do
|
81
81
|
let(:reason) { PactBroker::Matrix::NoEnvironmentSpecified.new }
|
82
82
|
|
83
|
-
its(:to_s) { is_expected.to start_with "WARN:
|
83
|
+
its(:to_s) { is_expected.to start_with "WARN: It is recommended to specify the environment" }
|
84
84
|
end
|
85
85
|
|
86
86
|
context "when the reason is SelectorWithoutPacticipantVersionNumberSpecified" do
|
87
87
|
let(:reason) { PactBroker::Matrix::SelectorWithoutPacticipantVersionNumberSpecified.new }
|
88
88
|
|
89
|
-
its(:to_s) { is_expected.to start_with "WARN:
|
89
|
+
its(:to_s) { is_expected.to start_with "WARN: It is recommended to specify the version number" }
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -23,12 +23,14 @@ module PactBroker
|
|
23
23
|
execution_date: DateTime.now,
|
24
24
|
provider_version_tags: provider_version_tags)
|
25
25
|
end
|
26
|
+
|
26
27
|
let(:pact_version) do
|
27
28
|
instance_double("PactBroker::Pacts::PactVersion", name: "Name")
|
28
29
|
end
|
29
30
|
|
30
31
|
let(:provider_version_tags) { [instance_double(PactBroker::Tags::TagWithLatestFlag, name: "prod", latest?: true)] }
|
31
32
|
let(:pact) { instance_double("PactBroker::Domain::Pact", name: "Some pact", consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "1.2.3") }
|
33
|
+
let(:is_pending) { true }
|
32
34
|
let(:options) { {base_url: "http://example.org", consumer_name: "Foo", consumer_version_number: "1.2.3", resource_url: "http://self"} }
|
33
35
|
|
34
36
|
subject { JSON.parse VerificationSummaryDecorator.new(summary).to_json(user_options: options), symbolize_names: true }
|
@@ -8,7 +8,6 @@ module PactBroker
|
|
8
8
|
describe "from_json" do
|
9
9
|
let(:hash) do
|
10
10
|
{
|
11
|
-
branch: "branch",
|
12
11
|
buildUrl: "buildUrl",
|
13
12
|
tags: [{ name: "main" }]
|
14
13
|
}
|
@@ -17,7 +16,6 @@ module PactBroker
|
|
17
16
|
subject { VersionDecorator.new(OpenStruct.new).from_json(hash.to_json) }
|
18
17
|
|
19
18
|
it "sets the properties" do
|
20
|
-
expect(subject.branch).to eq "branch"
|
21
19
|
expect(subject.build_url).to eq "buildUrl"
|
22
20
|
expect(subject.tags.first.name).to eq "main"
|
23
21
|
end
|
@@ -32,7 +30,7 @@ module PactBroker
|
|
32
30
|
TestDataBuilder.new
|
33
31
|
.create_consumer("Consumer")
|
34
32
|
.create_provider("providerA")
|
35
|
-
.create_consumer_version("1.2.3")
|
33
|
+
.create_consumer_version("1.2.3", branch: "main")
|
36
34
|
.create_consumer_version_tag("prod")
|
37
35
|
.create_pact
|
38
36
|
.create_provider("ProviderB")
|
@@ -85,6 +83,12 @@ module PactBroker
|
|
85
83
|
expect(subject[:_embedded][:tags].first[:name]).to eq "prod"
|
86
84
|
end
|
87
85
|
|
86
|
+
it "includes the branches" do
|
87
|
+
expect(subject[:_embedded][:branches]).to be_instance_of(Array)
|
88
|
+
expect(subject[:_embedded][:branches].first[:name]).to eq "main"
|
89
|
+
expect(subject[:_embedded][:branches].first[:latest]).to eq true
|
90
|
+
end
|
91
|
+
|
88
92
|
it "includes the timestamps" do
|
89
93
|
expect(subject[:createdAt]).to_not be nil
|
90
94
|
end
|
@@ -6,7 +6,7 @@ module PactBroker
|
|
6
6
|
module Decorators
|
7
7
|
describe WebhookExecutionResultDecorator do
|
8
8
|
describe "to_json" do
|
9
|
-
let(:webhook_execution_result) { PactBroker::Webhooks::WebhookExecutionResult.new(request, response, logs, error) }
|
9
|
+
let(:webhook_execution_result) { PactBroker::Webhooks::WebhookExecutionResult.new(request, response, true, logs, error) }
|
10
10
|
let(:logs) { "logs" }
|
11
11
|
let(:headers) { { "Something" => ["blah", "thing"]} }
|
12
12
|
let(:request) do
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "pact_broker/api/middleware/configuration"
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Api
|
5
|
+
module Middleware
|
6
|
+
class TestApp
|
7
|
+
def call(_)
|
8
|
+
[200, {}, [PactBroker.configuration.allow_dangerous_contract_modification.to_s]]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Configuration do
|
13
|
+
describe "#call" do
|
14
|
+
let(:configuration) do
|
15
|
+
conf = PactBroker::Configuration.default_configuration
|
16
|
+
conf.allow_dangerous_contract_modification = false
|
17
|
+
conf
|
18
|
+
end
|
19
|
+
let(:app) { Configuration.new(TestApp.new, configuration) }
|
20
|
+
let(:rack_env) { {} }
|
21
|
+
|
22
|
+
subject { get("/", nil, rack_env) }
|
23
|
+
|
24
|
+
context "with no overrides" do
|
25
|
+
it "uses the default configuration" do
|
26
|
+
expect(subject.body).to eq "false"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with overrides" do
|
31
|
+
let(:rack_env) do
|
32
|
+
{ "pactbroker.configuration_overrides" => { allow_dangerous_contract_modification: true }}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "overrides the configuration for the duration of the request" do
|
36
|
+
expect(subject.body).to eq "true"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "spec_helper"
|
2
1
|
require "pact_broker/api/resources/verifications"
|
3
2
|
require "pact_broker/pacts/service"
|
4
3
|
require "pact_broker/verifications/service"
|
@@ -17,7 +16,7 @@ module PactBroker
|
|
17
16
|
let(:database_connector) { double("database_connector" )}
|
18
17
|
let(:verification) { double(PactBroker::Domain::Verification) }
|
19
18
|
let(:errors_empty) { true }
|
20
|
-
let(:parsed_metadata) { { the: "metadata", consumer_version_number: "2"} }
|
19
|
+
let(:parsed_metadata) { { the: "metadata", consumer_version_number: "2", pending: true } }
|
21
20
|
let(:base_url) { "http://example.org" }
|
22
21
|
let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration) }
|
23
22
|
|
@@ -62,11 +61,14 @@ module PactBroker
|
|
62
61
|
|
63
62
|
before do
|
64
63
|
allow(Pacts::Service).to receive(:find_pact).and_return(pact)
|
64
|
+
allow(Pacts::Service).to receive(:find_for_verification_publication).and_return(verified_pacts)
|
65
65
|
allow(PactBroker::Verifications::Service).to receive(:next_number).and_return(next_verification_number)
|
66
66
|
allow(PactBroker::Api::Decorators::VerificationDecorator).to receive(:new).and_return(decorator)
|
67
67
|
allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return("some-boolean")
|
68
68
|
end
|
69
69
|
|
70
|
+
let(:verified_pacts) { double("verified pacts") }
|
71
|
+
|
70
72
|
it "parses the webhook metadata" do
|
71
73
|
expect(PactBrokerUrls).to receive(:decode_pact_metadata).with("abcd")
|
72
74
|
subject
|
@@ -83,8 +85,8 @@ module PactBroker
|
|
83
85
|
it "stores the verification in the database" do
|
84
86
|
expect(PactBroker::Verifications::Service).to receive(:create).with(
|
85
87
|
next_verification_number,
|
86
|
-
hash_including("some" => "params", "wip" => false),
|
87
|
-
|
88
|
+
hash_including("some" => "params", "wip" => false, "pending" => true),
|
89
|
+
verified_pacts,
|
88
90
|
parsed_metadata
|
89
91
|
)
|
90
92
|
subject
|
@@ -30,7 +30,7 @@ module PactBroker
|
|
30
30
|
let(:pact) { instance_double("PactBroker::Domain::Pact") }
|
31
31
|
let(:consumer_name) { "foo" }
|
32
32
|
let(:provider_name) { "bar" }
|
33
|
-
let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration, webhook_context: event_context) }
|
33
|
+
let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration, retry_schedule: [], webhook_context: event_context) }
|
34
34
|
let(:event_context) { { some: "data" } }
|
35
35
|
|
36
36
|
before do
|
@@ -203,6 +203,18 @@ module PactBroker
|
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
+
context "when the pseudo_branch_verification_status is :failed_pending" do
|
207
|
+
let(:pseudo_branch_verification_status) { :failed_pending }
|
208
|
+
let(:expected_color) { "red" }
|
209
|
+
let(:expected_right_text) { "failed%20%28pending%29" }
|
210
|
+
|
211
|
+
it "create a red badge with left text 'failed'" do
|
212
|
+
subject
|
213
|
+
expect(http_request).to have_been_made
|
214
|
+
expect(pact_verification_badge_url).to eq URI(expected_url)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
206
218
|
context "when the pseudo_branch_verification_status is :stale" do
|
207
219
|
let(:pseudo_branch_verification_status) { :stale }
|
208
220
|
let(:expected_color) { "orange" }
|
@@ -248,6 +260,16 @@ module PactBroker
|
|
248
260
|
end
|
249
261
|
end
|
250
262
|
|
263
|
+
# TODO save a static image for this
|
264
|
+
context "when the pseudo_branch_verification_status is failed_pending" do
|
265
|
+
let(:pseudo_branch_verification_status) { :failed_pending }
|
266
|
+
|
267
|
+
it "returns a static failed image" do
|
268
|
+
expect(subject).to include ">pact</"
|
269
|
+
expect(subject).to include ">failed</"
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
251
273
|
context "when the pseudo_branch_verification_status is stale" do
|
252
274
|
let(:pseudo_branch_verification_status) { :stale }
|
253
275
|
|
@@ -39,7 +39,7 @@ module PactBroker
|
|
39
39
|
|
40
40
|
it "sets the version branch" do
|
41
41
|
subject
|
42
|
-
expect(PactBroker::Domain::Version.order(:id).last.
|
42
|
+
expect(PactBroker::Domain::Version.order(:id).last.branch_names).to include "main"
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns a results object" do
|
@@ -60,6 +60,27 @@ module PactBroker
|
|
60
60
|
expect(subject.notices.find{ |log| log.type == "success" && log.text.include?(" published ") }).to_not be nil
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
context "when no branch is specified but tags are" do
|
65
|
+
before do
|
66
|
+
allow(PactBroker.configuration).to receive(:use_first_tag_as_branch).and_return(true)
|
67
|
+
end
|
68
|
+
|
69
|
+
let(:contracts_to_publish) do
|
70
|
+
ContractsToPublish.from_hash(
|
71
|
+
pacticipant_name: "Foo",
|
72
|
+
pacticipant_version_number: "1",
|
73
|
+
tags: ["a", "b"],
|
74
|
+
branch: nil,
|
75
|
+
contracts: contracts
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "uses the first tag as the branch" do
|
80
|
+
subject
|
81
|
+
expect(PactBroker::Domain::Version.order(:id).last.branch_versions.collect(&:branch_name)).to eq ["a"]
|
82
|
+
end
|
83
|
+
end
|
63
84
|
end
|
64
85
|
|
65
86
|
context "when the pact already exists" do
|
@@ -74,8 +95,8 @@ module PactBroker
|
|
74
95
|
expect { subject }.to change { PactBroker::Domain::Version.order(:id).last.tags.count}.from(1).to(3)
|
75
96
|
end
|
76
97
|
|
77
|
-
it "
|
78
|
-
expect { subject }.to change { PactBroker::Domain::Version.order(:id).last.
|
98
|
+
it "adds the branch to the existing version" do
|
99
|
+
expect { subject }.to change { PactBroker::Domain::Version.order(:id).last.branch_versions.collect(&:branch_name)}.from(["feat/x"]).to(["feat/x", "main"])
|
79
100
|
end
|
80
101
|
|
81
102
|
context "when the write mode is overwrite" do
|
@@ -14,8 +14,8 @@ module PactBroker
|
|
14
14
|
let(:db) { PactBroker::DB.connection }
|
15
15
|
|
16
16
|
subject { Clean.call(PactBroker::DB.connection, options) }
|
17
|
-
let(:latest_dev_selector) {
|
18
|
-
let(:all_prod_selector) {
|
17
|
+
let(:latest_dev_selector) { { tag: "dev", latest: true } }
|
18
|
+
let(:all_prod_selector) { { tag: "prod" } }
|
19
19
|
|
20
20
|
describe ".call"do
|
21
21
|
context "when there are specified versions to keep" do
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "pact_broker/db/data_migrations/create_branches"
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module DB
|
5
|
+
module DataMigrations
|
6
|
+
describe CreateBranches do
|
7
|
+
let(:db) { PactBroker::Domain::Version.db }
|
8
|
+
|
9
|
+
subject { CreateBranches.call(db) }
|
10
|
+
|
11
|
+
context "when there are no branch objects" do
|
12
|
+
before do
|
13
|
+
td.create_pacticipant("Foo")
|
14
|
+
.create_version("1")
|
15
|
+
.create_version("2")
|
16
|
+
.create_version("3")
|
17
|
+
.create_pacticipant("Bar")
|
18
|
+
.create_version("10")
|
19
|
+
.create_version("11")
|
20
|
+
.create_version("12")
|
21
|
+
|
22
|
+
db[:versions].where(number: ["1", "2"]).update(branch: "main")
|
23
|
+
db[:versions].where(number: ["10", "11"]).update(branch: "main")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "creates the missing branch versions" do
|
27
|
+
subject
|
28
|
+
expect(db[:branches].count).to eq 2
|
29
|
+
expect(db[:branch_heads].count).to eq 2
|
30
|
+
expect(db[:branch_versions].count).to eq 4
|
31
|
+
expect(db[:branch_heads].order(:branch_id).first[:version_id]).to eq db[:versions].where(number: "2").single_record[:id]
|
32
|
+
expect(db[:branch_heads].order(:branch_id).last[:version_id]).to eq db[:versions].where(number: "11").single_record[:id]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when there is a branch already" do
|
37
|
+
before do
|
38
|
+
td.create_pacticipant("Foo")
|
39
|
+
.create_version("1", branch: "main")
|
40
|
+
.create_version("2")
|
41
|
+
.create_version("3", branch: "main")
|
42
|
+
.create_version("4")
|
43
|
+
db[:versions].where(number: ["1", "2"]).update(branch: "main")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "creates the missing branch versionsq" do
|
47
|
+
subject
|
48
|
+
expect(db[:branches].count).to eq 1
|
49
|
+
expect(db[:branch_heads].count).to eq 1
|
50
|
+
expect(db[:branch_versions].count).to eq 3
|
51
|
+
expect(db[:branch_heads].order(:branch_id).last[:version_id]).to eq db[:versions].where(number: "3").single_record[:id]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -5,22 +5,22 @@ module PactBroker
|
|
5
5
|
module Diagnostic
|
6
6
|
module Resources
|
7
7
|
describe Dependencies do
|
8
|
-
|
9
8
|
describe "GET /diagnostic/status/dependencies" do
|
10
|
-
|
11
9
|
include Rack::Test::Methods
|
12
10
|
|
11
|
+
let(:rack_env) { { "pactbroker.base_url" => "http://pact-broker"} }
|
13
12
|
let(:app) { PactBroker::Diagnostic::App.new }
|
14
13
|
let(:parsed_response_body) { JSON.parse(subject.body) }
|
15
14
|
|
16
|
-
|
15
|
+
|
16
|
+
subject { get("/diagnostic/status/dependencies", nil, rack_env) }
|
17
17
|
|
18
18
|
it "returns application/hal+json" do
|
19
19
|
expect(subject.headers["Content-Type"]).to eq "application/hal+json"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "returns a link to itself" do
|
23
|
-
expect(parsed_response_body["_links"]["self"]["href"]).to eq "http://
|
23
|
+
expect(parsed_response_body["_links"]["self"]["href"]).to eq "http://pact-broker/diagnostic/status/dependencies"
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when we can connect to the database" do
|
@@ -6,16 +6,15 @@ module PactBroker
|
|
6
6
|
module Diagnostic
|
7
7
|
module Resources
|
8
8
|
describe Heartbeat do
|
9
|
-
|
10
9
|
include Rack::Test::Methods
|
11
10
|
|
12
11
|
let(:app) { PactBroker::Diagnostic::App.new }
|
13
12
|
|
14
13
|
describe "GET /diagnostic/status/heartbeat" do
|
15
|
-
|
14
|
+
let(:rack_env) { { "pactbroker.base_url" => "http://pact-broker"} }
|
16
15
|
let(:parsed_response_body) { JSON.parse(subject.body) }
|
17
16
|
|
18
|
-
subject { get
|
17
|
+
subject { get("/diagnostic/status/heartbeat", nil, rack_env) }
|
19
18
|
|
20
19
|
it "returns a 200" do
|
21
20
|
expect(subject.status).to eq 200
|
@@ -26,7 +25,7 @@ module PactBroker
|
|
26
25
|
end
|
27
26
|
|
28
27
|
it "returns a link to itself" do
|
29
|
-
expect(parsed_response_body["_links"]["self"]["href"]).to eq "http://
|
28
|
+
expect(parsed_response_body["_links"]["self"]["href"]).to eq "http://pact-broker/diagnostic/status/heartbeat"
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -13,7 +13,7 @@ module PactBroker
|
|
13
13
|
allow(webhook_executions).to receive(:sort).and_return(webhook_executions)
|
14
14
|
end
|
15
15
|
|
16
|
-
subject { IndexItem.create(nil, nil, nil, true, nil, [], webhook_executions) }
|
16
|
+
subject { IndexItem.create(nil, nil, nil, nil, true, nil, [], webhook_executions) }
|
17
17
|
|
18
18
|
it "returns the created_at date of the last execution" do
|
19
19
|
expect(subject.last_webhook_execution_date).to eq DateTime.new(2015)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "pact_broker/domain/version"
|
2
|
+
require "pact_broker/db/clean/selector"
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Domain
|
@@ -131,7 +132,7 @@ module PactBroker
|
|
131
132
|
.create_consumer_version("3", tag_names: %w{master})
|
132
133
|
end
|
133
134
|
|
134
|
-
let(:selector) { PactBroker::
|
135
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(tag: "master", max_age: max_age) }
|
135
136
|
|
136
137
|
let(:max_age) { 3 }
|
137
138
|
let(:four_days_ago) { Date.today - 4 }
|
@@ -141,6 +142,76 @@ module PactBroker
|
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
145
|
+
context "when selecting the latest version for each branch" do
|
146
|
+
before do
|
147
|
+
td.create_consumer("Foo")
|
148
|
+
.create_consumer_version("1", branch: "main")
|
149
|
+
.create_consumer_version("2", branch: "main")
|
150
|
+
.create_consumer("Bar")
|
151
|
+
.create_consumer_version("3", branch: "main")
|
152
|
+
end
|
153
|
+
|
154
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(branch: true, latest: true) }
|
155
|
+
|
156
|
+
it "selects the consumer versions that are the latest for their branches" do
|
157
|
+
expect(version_numbers).to eq %w{2 3}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "when selecting all versions with a branch" do
|
162
|
+
before do
|
163
|
+
td.create_consumer("Foo")
|
164
|
+
.create_consumer_version("1", branch: "main")
|
165
|
+
.create_consumer_version("2")
|
166
|
+
.create_consumer("Bar")
|
167
|
+
.create_consumer_version("3", branch: "main")
|
168
|
+
end
|
169
|
+
|
170
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(branch: true, latest: true) }
|
171
|
+
|
172
|
+
it "selects the consumer versions that are the latest for their branches" do
|
173
|
+
expect(version_numbers).to eq %w{1 3}
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when selecting the latest versions from the main branches" do
|
178
|
+
before do
|
179
|
+
td.create_consumer("Foo", main_branch: "main")
|
180
|
+
.create_consumer_version("1", branch: "main")
|
181
|
+
.create_consumer_version("2", branch: "main")
|
182
|
+
.create_consumer_version("3", branch: "not-main")
|
183
|
+
.create_consumer("Bar", main_branch: "develop")
|
184
|
+
.create_consumer_version("4", branch: "develop")
|
185
|
+
.create_consumer_version("5", branch: "develop")
|
186
|
+
.create_consumer_version("6", branch: "main")
|
187
|
+
end
|
188
|
+
|
189
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(main_branch: true, latest: true) }
|
190
|
+
|
191
|
+
it "selects the consumer versions that are the latest for their branches" do
|
192
|
+
expect(version_numbers).to eq %w{2 5}
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "when selecting all versions from the main branches" do
|
197
|
+
before do
|
198
|
+
td.create_consumer("Foo", main_branch: "main")
|
199
|
+
.create_consumer_version("1", branch: "main")
|
200
|
+
.create_consumer_version("2", branch: "main")
|
201
|
+
.create_consumer_version("3", branch: "not-main")
|
202
|
+
.create_consumer("Bar", main_branch: "develop")
|
203
|
+
.create_consumer_version("4", branch: "develop")
|
204
|
+
.create_consumer_version("5", branch: "develop")
|
205
|
+
.create_consumer_version("6", branch: "main")
|
206
|
+
end
|
207
|
+
|
208
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(main_branch: true) }
|
209
|
+
|
210
|
+
it "selects the consumer versions that are the latest for their branches" do
|
211
|
+
expect(version_numbers).to eq %w{1 2 4 5}
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
144
215
|
context "when selecting all versions of a pacticipant currently deployed to an environment" do
|
145
216
|
let(:selector) { PactBroker::Matrix::UnresolvedSelector.new(environment_name: "prod", pacticipant_name: "Foo") }
|
146
217
|
|
@@ -194,6 +265,60 @@ module PactBroker
|
|
194
265
|
end
|
195
266
|
end
|
196
267
|
|
268
|
+
context "when selecting all currently deployed versions" do
|
269
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(deployed: true) }
|
270
|
+
|
271
|
+
before do
|
272
|
+
td.create_environment("test")
|
273
|
+
.create_consumer("Foo")
|
274
|
+
.create_consumer_version("1")
|
275
|
+
.create_deployed_version_for_consumer_version(target: "1")
|
276
|
+
.create_consumer_version("2")
|
277
|
+
.create_environment("prod")
|
278
|
+
.create_deployed_version_for_consumer_version(target: "2")
|
279
|
+
.create_consumer_version("3")
|
280
|
+
.create_consumer_version("5")
|
281
|
+
.create_consumer("Bar")
|
282
|
+
.create_consumer_version("10")
|
283
|
+
.create_deployed_version_for_consumer_version(target: "3")
|
284
|
+
.create_consumer_version("11")
|
285
|
+
.create_deployed_version_for_consumer_version(currently_deployed: false)
|
286
|
+
.create_consumer_version("12")
|
287
|
+
.create_released_version_for_consumer_version
|
288
|
+
end
|
289
|
+
|
290
|
+
it "returns the versions that are currently deployed" do
|
291
|
+
expect(version_numbers).to eq %w{1 2 10}
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "when selecting all currently released+supported versions" do
|
296
|
+
let(:selector) { PactBroker::DB::Clean::Selector.new(released: true) }
|
297
|
+
|
298
|
+
before do
|
299
|
+
td.create_environment("test")
|
300
|
+
.create_consumer("Foo")
|
301
|
+
.create_consumer_version("1")
|
302
|
+
.create_released_version_for_consumer_version
|
303
|
+
.create_consumer_version("2")
|
304
|
+
.create_environment("prod")
|
305
|
+
.create_released_version_for_consumer_version
|
306
|
+
.create_consumer_version("3")
|
307
|
+
.create_consumer_version("5")
|
308
|
+
.create_consumer("Bar")
|
309
|
+
.create_consumer_version("10")
|
310
|
+
.create_released_version_for_consumer_version
|
311
|
+
.create_consumer_version("11")
|
312
|
+
.create_released_version_for_consumer_version(currently_supported: false)
|
313
|
+
.create_consumer_version("12")
|
314
|
+
.create_deployed_version_for_consumer_version
|
315
|
+
end
|
316
|
+
|
317
|
+
it "returns the versions that are currently released+supported" do
|
318
|
+
expect(version_numbers).to eq %w{1 2 10}
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
197
322
|
context "selecting versions for a branch" do
|
198
323
|
before do
|
199
324
|
td.create_consumer("Foo")
|
@@ -277,40 +402,6 @@ module PactBroker
|
|
277
402
|
end
|
278
403
|
end
|
279
404
|
|
280
|
-
describe "latest_version_for_branch" do
|
281
|
-
before do
|
282
|
-
td.create_consumer("Foo")
|
283
|
-
.create_consumer_version("1", branch: "main")
|
284
|
-
.create_consumer_version("2", branch: "main")
|
285
|
-
.create_consumer_version("3", branch: "feat/x")
|
286
|
-
.create_consumer_version("4", branch: "feat/x")
|
287
|
-
.create_consumer_version("5")
|
288
|
-
end
|
289
|
-
|
290
|
-
subject { Version.order(:order) }
|
291
|
-
|
292
|
-
it "lazy loads" do
|
293
|
-
expect(subject.all[0].latest_version_for_branch.number).to eq "2"
|
294
|
-
expect(subject.all[2].latest_version_for_branch.number).to eq "4"
|
295
|
-
expect(subject.all[4].latest_version_for_branch).to eq nil
|
296
|
-
end
|
297
|
-
|
298
|
-
it "eager loads" do
|
299
|
-
all = subject.eager(:latest_version_for_branch).all
|
300
|
-
|
301
|
-
expect(all[0].associations[:latest_version_for_branch]).to_not be nil
|
302
|
-
expect(all[1].associations[:latest_version_for_branch]).to_not be nil
|
303
|
-
expect(all[2].associations[:latest_version_for_branch]).to_not be nil
|
304
|
-
expect(all[3].associations[:latest_version_for_branch]).to_not be nil
|
305
|
-
expect(all[4].associations.fetch(:latest_version_for_branch)).to be nil
|
306
|
-
|
307
|
-
expect(all[0].latest_version_for_branch.number).to eq "2"
|
308
|
-
expect(all[1].latest_version_for_branch.number).to eq "2"
|
309
|
-
expect(all[2].latest_version_for_branch.number).to eq "4"
|
310
|
-
expect(all[4].latest_version_for_branch).to eq nil
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
405
|
describe "#latest_pact_publication" do
|
315
406
|
let!(:pact) do
|
316
407
|
TestDataBuilder.new
|
@@ -367,7 +458,7 @@ module PactBroker
|
|
367
458
|
context "when there is no branch" do
|
368
459
|
let(:version) { Version.for("Foo", "3") }
|
369
460
|
|
370
|
-
it { is_expected.to be
|
461
|
+
it { is_expected.to be false }
|
371
462
|
end
|
372
463
|
end
|
373
464
|
|