pact_broker 2.76.0 → 2.78.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +12 -0
- data/.github/workflows/test-ruby-3.yml +19 -0
- data/.github/workflows/test.yml +19 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +47 -0
- data/DEVELOPER_SETUP.md +62 -3
- data/Dockerfile +1 -0
- data/ISSUES.md +12 -4
- data/README.md +1 -1
- data/config.ru +1 -0
- data/db/ddl_statements/head_pact_tags.rb +24 -1
- data/db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb +11 -0
- data/db/ddl_statements/latest_tagged_pact_publications.rb +6 -0
- data/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +13 -0
- data/db/migrations/20210117_add_branch_to_version.rb +9 -0
- data/db/migrations/20210202_add_created_at_to_head_pact_tags.rb +14 -0
- data/db/migrations/20210205_add_pacticipant_id_to_tag.rb +17 -0
- data/db/migrations/20210206_add_index_to_tags_and_versions.rb +27 -0
- data/db/migrations/20210207_optimise_latest_verification_ids_for_consumer_version_tags.rb +13 -0
- data/db/migrations/20210208_optimise_latest_tagged_pact_cv_orders.rb +13 -0
- data/db/migrations/20210210_create_environments_table.rb +16 -0
- data/docker-compose-issue-repro-with-pact-broker-docker-image.yml +16 -5
- data/lib/pact_broker/api.rb +7 -2
- data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +8 -0
- data/lib/pact_broker/api/contracts/environment_schema.rb +49 -0
- data/lib/pact_broker/api/decorators/base_decorator.rb +11 -0
- data/lib/pact_broker/api/decorators/dashboard_decorator.rb +5 -1
- data/lib/pact_broker/api/decorators/environment_decorator.rb +30 -0
- data/lib/pact_broker/api/decorators/environments_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/matrix_decorator.rb +8 -2
- data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -2
- data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +2 -0
- data/lib/pact_broker/api/decorators/version_decorator.rb +15 -2
- data/lib/pact_broker/api/pact_broker_urls.rb +8 -0
- data/lib/pact_broker/api/resources/default_base_resource.rb +13 -0
- data/lib/pact_broker/api/resources/environment.rb +76 -0
- data/lib/pact_broker/api/resources/environments.rb +75 -0
- data/lib/pact_broker/api/resources/index.rb +20 -0
- data/lib/pact_broker/api/resources/latest_version.rb +27 -0
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +1 -0
- data/lib/pact_broker/api/resources/verifications.rb +5 -2
- data/lib/pact_broker/api/resources/version.rb +15 -9
- data/lib/pact_broker/api/resources/webhook_execution.rb +1 -1
- data/lib/pact_broker/app.rb +0 -2
- data/lib/pact_broker/certificates/certificate.rb +1 -1
- data/lib/pact_broker/config/setting.rb +1 -1
- data/lib/pact_broker/config/space_delimited_integer_list.rb +25 -0
- data/lib/pact_broker/configuration.rb +18 -1
- data/lib/pact_broker/db/data_migrations/helpers.rb +4 -0
- data/lib/pact_broker/db/data_migrations/set_extra_columns_for_tags.rb +29 -0
- data/lib/pact_broker/db/migrate_data.rb +1 -0
- data/lib/pact_broker/db/seed_example_data.rb +13 -13
- data/lib/pact_broker/deployments/environment.rb +15 -0
- data/lib/pact_broker/deployments/environment_service.rb +39 -0
- data/lib/pact_broker/doc/views/index/environment.markdown +37 -0
- data/lib/pact_broker/doc/views/index/environments.markdown +53 -0
- data/lib/pact_broker/doc/views/index/latest-pact-versions.markdown +1 -1
- data/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown +1 -0
- data/lib/pact_broker/doc/views/index/pacticipant-version.markdown +13 -0
- data/lib/pact_broker/domain/index_item.rb +18 -4
- data/lib/pact_broker/domain/pacticipant.rb +9 -5
- data/lib/pact_broker/domain/tag.rb +131 -71
- data/lib/pact_broker/domain/verification.rb +3 -2
- data/lib/pact_broker/domain/version.rb +58 -23
- data/lib/pact_broker/domain/webhook.rb +12 -9
- data/lib/pact_broker/hash_refinements.rb +4 -0
- data/lib/pact_broker/index/service.rb +55 -49
- data/lib/pact_broker/locale/en.yml +3 -1
- data/lib/pact_broker/matrix/quick_row.rb +8 -0
- data/lib/pact_broker/metrics/service.rb +1 -1
- data/lib/pact_broker/pacts/eager_loaders.rb +52 -0
- data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +18 -13
- data/lib/pact_broker/pacts/lazy_loaders.rb +14 -0
- data/lib/pact_broker/pacts/pact_publication.rb +38 -84
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +297 -0
- data/lib/pact_broker/pacts/pact_version.rb +1 -2
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +286 -0
- data/lib/pact_broker/pacts/repository.rb +5 -231
- data/lib/pact_broker/pacts/selected_pact.rb +4 -0
- data/lib/pact_broker/pacts/selector.rb +56 -1
- data/lib/pact_broker/pacts/selectors.rb +16 -0
- data/lib/pact_broker/pacts/service.rb +6 -8
- data/lib/pact_broker/pacts/squash_pacts_for_verification.rb +1 -4
- data/lib/pact_broker/pacts/verifiable_pact.rb +45 -2
- data/lib/pact_broker/pacts/verifiable_pact_messages.rb +56 -16
- data/lib/pact_broker/repositories/helpers.rb +4 -0
- data/lib/pact_broker/services.rb +9 -0
- data/lib/pact_broker/tags/eager_loaders.rb +47 -0
- data/lib/pact_broker/tags/repository.rb +3 -1
- data/lib/pact_broker/tags/service.rb +0 -3
- data/lib/pact_broker/tags/tag_with_latest_flag.rb +1 -0
- data/lib/pact_broker/test/http_test_data_builder.rb +92 -26
- data/lib/pact_broker/test/test_data_builder.rb +50 -3
- data/lib/pact_broker/ui/app.rb +6 -0
- data/lib/pact_broker/ui/controllers/base_controller.rb +5 -1
- data/lib/pact_broker/ui/controllers/pacts.rb +18 -0
- data/lib/pact_broker/ui/view_models/index_item.rb +9 -0
- data/lib/pact_broker/ui/view_models/matrix_line.rb +36 -0
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +8 -0
- data/lib/pact_broker/ui/views/matrix/show.haml +10 -0
- data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +7 -5
- data/lib/pact_broker/verifications/service.rb +2 -1
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/eager_loaders.rb +71 -0
- data/lib/pact_broker/versions/lazy_loaders.rb +13 -0
- data/lib/pact_broker/versions/repository.rb +22 -2
- data/lib/pact_broker/versions/service.rb +5 -1
- data/lib/pact_broker/webhooks/execution.rb +3 -2
- data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +2 -0
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +10 -3
- data/lib/pact_broker/webhooks/service.rb +8 -7
- data/lib/pact_broker/webhooks/trigger_service.rb +56 -23
- data/lib/pact_broker/webhooks/triggered_webhook.rb +14 -5
- data/lib/pact_broker/webhooks/webhook.rb +1 -1
- data/lib/pact_broker/webhooks/webhook_event.rb +1 -1
- data/lib/pact_broker/webhooks/webhook_execution_result.rb +6 -1
- data/lib/pact_broker/webhooks/webhook_request_logger.rb +7 -1
- data/lib/sequel/plugins/upsert.rb +18 -4
- data/public/stylesheets/index.css +22 -1
- data/public/stylesheets/matrix.css +0 -21
- data/regression/can_i_deploy_spec.rb +5 -4
- data/regression/index_spec.rb +26 -0
- data/regression/regression_helper.rb +29 -3
- data/regression/script/clear.sh +3 -0
- data/regression/script/run.sh +3 -0
- data/script/demonstrate-version-branches.rb +33 -0
- data/script/pry.rb +2 -2
- data/script/reproduce-issue-starting-up.rb +13 -23
- data/script/reproduce-issue.rb +2 -1
- data/script/trigger-release.sh +1 -1
- data/script/webhook-server.ru +5 -5
- data/spec/features/create_environment_spec.rb +47 -0
- data/spec/features/create_tag_spec.rb +32 -0
- data/spec/features/create_version_spec.rb +70 -0
- data/spec/features/delete_environment_spec.rb +16 -0
- data/spec/features/end_deployment_spec.rb +29 -0
- data/spec/features/get_environment_spec.rb +19 -0
- data/spec/features/get_environments_spec.rb +20 -0
- data/spec/features/record_deployment_spec.rb +28 -0
- data/spec/features/update_environment_spec.rb +44 -0
- data/spec/fixtures/approvals/modifiable_resources.approved.json +6 -0
- data/spec/fixtures/dashboard.json +4 -2
- data/spec/integration/ui/index_spec.rb +4 -4
- data/spec/lib/pact_broker/api/contracts/environment_schema_spec.rb +83 -0
- data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +4 -2
- data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +11 -6
- data/spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb +6 -6
- data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +6 -0
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +18 -0
- data/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +4 -0
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +2 -5
- data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +56 -0
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +3 -2
- data/spec/lib/pact_broker/config/space_delimited_integer_list_spec.rb +47 -0
- data/spec/lib/pact_broker/configuration_spec.rb +12 -0
- data/spec/lib/pact_broker/domain/tag_spec.rb +101 -27
- data/spec/lib/pact_broker/domain/version_spec.rb +103 -15
- data/spec/lib/pact_broker/domain/webhook_spec.rb +7 -7
- data/spec/lib/pact_broker/index/service_spec.rb +89 -15
- data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +400 -0
- data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +434 -14
- data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +224 -0
- data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +46 -7
- data/spec/lib/pact_broker/pacts/selector_spec.rb +3 -2
- data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +2 -3
- data/spec/lib/pact_broker/pacts/service_spec.rb +9 -7
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +57 -10
- data/spec/lib/pact_broker/tags/repository_spec.rb +2 -0
- data/spec/lib/pact_broker/verifications/service_spec.rb +4 -1
- data/spec/lib/pact_broker/versions/repository_spec.rb +54 -0
- data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -5
- data/spec/lib/pact_broker/webhooks/service_spec.rb +13 -9
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +60 -18
- data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +8 -0
- data/spec/lib/sequel/plugins/upsert_spec.rb +31 -3
- data/spec/service_consumers/hal_relation_proxy_app.rb +3 -1
- data/spec/service_consumers/provider_states_for_pact_broker_client.rb +16 -0
- data/spec/spec_helper.rb +17 -5
- data/spec/support/approvals.rb +24 -0
- data/spec/support/shared_examples_for_responses.rb +11 -0
- data/tasks/db.rake +1 -0
- data/tasks/rspec.rake +1 -1
- metadata +67 -7
- data/docker-compose-issue-repro.yml +0 -22
- data/lib/rack/pact_broker/hal_browser_redirect.rb +0 -42
- data/spec/lib/rack/pact_broker/hal_browser_redirect_spec.rb +0 -27
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
|
4
|
+
$LOAD_PATH << "#{Dir.pwd}/lib"
|
5
|
+
require 'pact_broker/test/http_test_data_builder'
|
6
|
+
base_url = ENV['PACT_BROKER_BASE_URL'] || 'http://localhost:9292'
|
7
|
+
|
8
|
+
td = PactBroker::Test::HttpTestDataBuilder.new(base_url)
|
9
|
+
td.delete_integration(consumer: "Foo", provider: "Bar")
|
10
|
+
.delete_integration(consumer: "foo-consumer", provider: "bar-provider")
|
11
|
+
.publish_pact(consumer: "foo-consumer", consumer_version: "1", provider: "bar-provider", content_id: "111", branch: "main")
|
12
|
+
.publish_pact(consumer: "foo-consumer", consumer_version: "2", provider: "bar-provider", content_id: "222", tag: "feat/x")
|
13
|
+
.get_pacts_for_verification(
|
14
|
+
enable_pending: true,
|
15
|
+
provider_version_branch: "main",
|
16
|
+
provider_version_tag: "dev",
|
17
|
+
include_wip_pacts_since: "2020-01-01",
|
18
|
+
consumer_version_selectors: [{ branch: "main", latest: true }])
|
19
|
+
.verify_pact(
|
20
|
+
index: 0,
|
21
|
+
provider_version: "1",
|
22
|
+
success: true
|
23
|
+
)
|
24
|
+
.can_i_deploy(pacticipant: "bar-provider", version: "1", to: "prod")
|
25
|
+
.deploy_to_prod(pacticipant: "bar-provider", version: "1")
|
26
|
+
.can_i_deploy(pacticipant: "foo-consumer", version: "1", to: "prod")
|
27
|
+
.deploy_to_prod(pacticipant: "foo-consumer", version: "1")
|
28
|
+
|
29
|
+
rescue StandardError => e
|
30
|
+
puts "#{e.class} #{e.message}"
|
31
|
+
puts e.backtrace
|
32
|
+
exit 1
|
33
|
+
end
|
data/script/pry.rb
CHANGED
@@ -1,43 +1,33 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$LOAD_PATH << "#{Dir.pwd}/lib"
|
4
|
-
|
5
3
|
begin
|
6
4
|
|
5
|
+
$LOAD_PATH << "#{Dir.pwd}/lib"
|
7
6
|
require 'pact_broker/test/http_test_data_builder'
|
8
7
|
base_url = ENV['PACT_BROKER_BASE_URL'] || 'http://localhost:9292'
|
9
8
|
|
10
|
-
td = PactBroker::Test::HttpTestDataBuilder.new(base_url
|
11
|
-
td.delete_integration(consumer: "
|
12
|
-
.
|
13
|
-
.
|
14
|
-
.
|
15
|
-
.
|
9
|
+
td = PactBroker::Test::HttpTestDataBuilder.new(base_url)
|
10
|
+
td.delete_integration(consumer: "Foo", provider: "Bar")
|
11
|
+
.delete_integration(consumer: "foo-consumer", provider: "bar-provider")
|
12
|
+
.create_pacticipant("foo-consumer")
|
13
|
+
.create_pacticipant("foo-provider")
|
14
|
+
.create_global_webhook_for_verification_published(uuid: "ba8feb17-558a-4b3f-a078-f52c6fafd014", url: "http://webhook-server:9393")
|
15
|
+
.publish_pact(consumer: "foo-consumer", consumer_version: "1", provider: "bar-provider", content_id: "111", tag: "main")
|
16
|
+
.publish_pact(consumer: "foo-consumer", consumer_version: "2", provider: "bar-provider", content_id: "111", tag: ["feat/x", "feat/y"])
|
17
|
+
.sleep(10)
|
16
18
|
.get_pacts_for_verification(
|
17
|
-
enable_pending: true,
|
18
19
|
provider_version_tag: "main",
|
19
|
-
|
20
|
-
consumer_version_selectors: [{ tag: "main", latest: true }])
|
20
|
+
consumer_version_selectors: [{ tag: "main", latest: true }, { tag: "feat/x", latest: true }, { tag: "feat/y", latest: true }])
|
21
21
|
.verify_pact(
|
22
22
|
index: 0,
|
23
23
|
provider_version_tag: "main",
|
24
24
|
provider_version: "1",
|
25
|
-
success:
|
25
|
+
success: true
|
26
26
|
)
|
27
|
-
|
28
|
-
enable_pending: true,
|
29
|
-
provider_version_tag: "main",
|
30
|
-
include_wip_pacts_since: "2020-01-01",
|
31
|
-
consumer_version_selectors: [{ tag: "main", latest: true }])
|
32
|
-
.can_i_deploy(pacticipant: "MyProvider", version: "1", to: "prod")
|
33
|
-
.can_i_deploy(pacticipant: "MyConsumer", version: "1", to: "prod")
|
34
|
-
.deploy_to_prod(pacticipant: "MyProvider", version: "1")
|
35
|
-
.can_i_deploy(pacticipant: "MyConsumer", version: "1", to: "prod")
|
36
|
-
.deploy_to_prod(pacticipant: "MyConsumer", version: "1")
|
27
|
+
|
37
28
|
|
38
29
|
rescue StandardError => e
|
39
30
|
puts "#{e.class} #{e.message}"
|
40
31
|
puts e.backtrace
|
41
32
|
exit 1
|
42
33
|
end
|
43
|
-
|
data/script/reproduce-issue.rb
CHANGED
@@ -6,7 +6,8 @@ begin
|
|
6
6
|
base_url = ENV['PACT_BROKER_BASE_URL'] || 'http://localhost:9292'
|
7
7
|
|
8
8
|
td = PactBroker::Test::HttpTestDataBuilder.new(base_url)
|
9
|
-
td.delete_integration(consumer: "
|
9
|
+
td.delete_integration(consumer: "Foo", provider: "Bar")
|
10
|
+
.delete_integration(consumer: "foo-consumer", provider: "bar-provider")
|
10
11
|
.publish_pact(consumer: "foo-consumer", consumer_version: "1", provider: "bar-provider", content_id: "111", tag: "main")
|
11
12
|
.get_pacts_for_verification(
|
12
13
|
enable_pending: true,
|
data/script/trigger-release.sh
CHANGED
@@ -19,7 +19,7 @@ output=$(curl -v https://api.github.com/repos/${repository_slug}/dispatches \
|
|
19
19
|
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES" \
|
20
20
|
-d "{\"event_type\": \"release-triggered\", \"client_payload\": {\"increment\": ${increment}}}" 2>&1)
|
21
21
|
|
22
|
-
if ! echo "${output}" | grep "HTTP
|
22
|
+
if ! echo "${output}" | grep "HTTP\/.* 204" > /dev/null; then
|
23
23
|
echo "$output" | sed "s/${GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES}/********/g"
|
24
24
|
echo "Failed to trigger release"
|
25
25
|
exit 1
|
data/script/webhook-server.ru
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rack/utils'
|
2
|
+
STDOUT.sync = true
|
3
|
+
puts "Starting webhook server"
|
2
4
|
|
3
|
-
count = 0
|
4
5
|
run -> (env) {
|
5
|
-
|
6
|
-
|
7
|
-
puts Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
6
|
+
status = 200
|
7
|
+
puts Rack::Utils.parse_nested_query(env['QUERY_STRING']) if env['QUERY_STRING'] && env['QUERY_STRING'] != ''
|
8
8
|
puts env['rack.input'].read
|
9
|
-
[status, {}, ["
|
9
|
+
[status, {"Content-Type" => "text/plain"}, ["Webhook response.\n"]]
|
10
10
|
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'pact_broker/api/pact_broker_urls'
|
2
|
+
|
3
|
+
describe "Creating an environment" do
|
4
|
+
let(:path) { PactBroker::Api::PactBrokerUrls.environments_url }
|
5
|
+
let(:headers) { { "CONTENT_TYPE" => "application/json" } }
|
6
|
+
let(:response_body) { JSON.parse(subject.body, symbolize_names: true)}
|
7
|
+
let(:environment_hash) do
|
8
|
+
{
|
9
|
+
name: "test",
|
10
|
+
displayName: "Test",
|
11
|
+
production: false,
|
12
|
+
contacts: [
|
13
|
+
{ name: "Team Awesome", details: { email: "foo@bar.com", arbitraryThing: "thing" } }
|
14
|
+
]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { post(path, environment_hash.to_json, headers) }
|
19
|
+
|
20
|
+
it "returns a 201 response" do
|
21
|
+
expect(subject.status).to be 201
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the Location header" do
|
25
|
+
expect(subject.headers["Location"]).to eq PactBroker::Api::PactBrokerUrls.environment_url(PactBroker::Deployments::Environment.order(:id).last, "http://example.org")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a JSON Content Type" do
|
29
|
+
expect(subject.headers["Content-Type"]).to eq "application/hal+json;charset=utf-8"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the newly created environment" do
|
33
|
+
expect(response_body).to include environment_hash.merge(name: "test")
|
34
|
+
expect(response_body[:uuid]).to_not be nil
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with invalid params" do
|
38
|
+
before do
|
39
|
+
td.create_environment("test")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a 400 response" do
|
43
|
+
expect(subject.status).to be 400
|
44
|
+
expect(response_body[:errors]).to_not be nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
describe "Creating a tag" do
|
2
|
+
let(:path) { "/pacticipants/Foo/versions/1234/tags/foo" }
|
3
|
+
let(:headers) { { 'CONTENT_TYPE' => 'application/json' } }
|
4
|
+
let(:response_body) { JSON.parse(subject.body, symbolize_names: true)}
|
5
|
+
|
6
|
+
subject { put(path, {}, headers) }
|
7
|
+
|
8
|
+
it "returns a 201 response" do
|
9
|
+
expect(subject.status).to be 201
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns a HAL JSON Content Type" do
|
13
|
+
expect(subject.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the newly created tag" do
|
17
|
+
expect(response_body).to include name: "foo"
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when the tag already exists" do
|
21
|
+
before do
|
22
|
+
td.subtract_day
|
23
|
+
.create_consumer("Foo")
|
24
|
+
.create_consumer_version("1234")
|
25
|
+
.create_consumer_version_tag("foo")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a 200 response" do
|
29
|
+
expect(subject.status).to be 200
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
describe "Creating a pacticipant version" do
|
2
|
+
let(:path) { "/pacticipants/Foo/versions/1234" }
|
3
|
+
let(:headers) { { 'CONTENT_TYPE' => 'application/json' } }
|
4
|
+
let(:response_body) { JSON.parse(subject.body, symbolize_names: true)}
|
5
|
+
let(:version_hash) do
|
6
|
+
{
|
7
|
+
branch: "main",
|
8
|
+
buildUrl: "http://build",
|
9
|
+
tags: [{ name: "foo" }, { name: "bar" }]
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { put(path, version_hash.to_json, headers) }
|
14
|
+
|
15
|
+
it "returns a 201 response" do
|
16
|
+
expect(subject.status).to be 201
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns a HAL JSON Content Type" do
|
20
|
+
expect(subject.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the newly created version" do
|
24
|
+
expect(response_body).to include branch: "main", buildUrl: "http://build"
|
25
|
+
expect(response_body[:_embedded][:tags].size).to eq 2
|
26
|
+
end
|
27
|
+
|
28
|
+
it "creates the specified tags" do
|
29
|
+
expect { subject }.to change { PactBroker::Domain::Tag.count }.by(2)
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when the version already exists" do
|
33
|
+
before do
|
34
|
+
td.subtract_day
|
35
|
+
.create_consumer("Foo")
|
36
|
+
.create_consumer_version("1234", branch: "original-branch", build_url: "original-build-url")
|
37
|
+
.create_consumer_version_tag("dev")
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:version_hash) { { branch: "new-branch" } }
|
41
|
+
|
42
|
+
it "returns a 200" do
|
43
|
+
expect(subject.status).to be 200
|
44
|
+
end
|
45
|
+
|
46
|
+
it "overwrites the direct properties" do
|
47
|
+
expect(response_body[:branch]).to eq "new-branch"
|
48
|
+
expect(response_body).to_not have_key(:buildUrl)
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when not tags are specified" do
|
52
|
+
it "does not change the tags" do
|
53
|
+
expect { subject }.to_not change { PactBroker::Domain::Version.for("Foo", "1234").tags }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when tags are specified" do
|
58
|
+
let(:version_hash) { { branch: "new-branch", tags: [ { name: "main" }] } }
|
59
|
+
|
60
|
+
it "overwrites the tags" do
|
61
|
+
expect(response_body[:_embedded][:tags].size).to eq 1
|
62
|
+
expect(response_body[:_embedded][:tags].first[:name]).to eq "main"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "does not change the created date" do
|
67
|
+
expect { subject }.to_not change { PactBroker::Domain::Version.for("Foo", "1234").created_at }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'pact_broker/api/pact_broker_urls'
|
2
|
+
|
3
|
+
describe "Deleting an environment" do
|
4
|
+
before do
|
5
|
+
td.create_environment("test", uuid: "1234")
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:path) { PactBroker::Api::PactBrokerUrls.environment_url(td.and_return(:environment)) }
|
9
|
+
|
10
|
+
subject { delete(path, nil) }
|
11
|
+
|
12
|
+
it "returns a 204 response" do
|
13
|
+
subject
|
14
|
+
expect(last_response.status).to be 204
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# RPC style seems cleaner than REST here, as setting the endedAt parameter directly
|
3
|
+
# seems likely to end in Timezone tears
|
4
|
+
# This endpoint would be called by the pact broker client during `record-deployment` if the
|
5
|
+
# --end-previous-deployment (on by default) was specified.
|
6
|
+
# This allows us to know exactly what is deployed to a particular environment at a given time,
|
7
|
+
# (eg. /environments/test/deployments/current)
|
8
|
+
# and provides first class support for mobile clients that have multiple versions in prod
|
9
|
+
# at once.
|
10
|
+
|
11
|
+
describe "Record deployment ended", skip: "Not yet implemented" do
|
12
|
+
before do
|
13
|
+
td.create_environment("test")
|
14
|
+
.create_pacticipant("Foo")
|
15
|
+
.create_pacticipant_version("1")
|
16
|
+
.create_deployment("test")
|
17
|
+
end
|
18
|
+
let(:path) { "/pacticipants/Foo/deployments/test/latest/end" }
|
19
|
+
let(:headers) { {} }
|
20
|
+
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true) }
|
21
|
+
|
22
|
+
subject { post(path, nil, headers) }
|
23
|
+
|
24
|
+
it { is_expected.be_a_hal_json_success_response }
|
25
|
+
|
26
|
+
it "returns the updated deployment" do
|
27
|
+
expect(subject[:endedAt]).to_not be nil
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'pact_broker/api/pact_broker_urls'
|
2
|
+
|
3
|
+
describe "Get an environment" do
|
4
|
+
before do
|
5
|
+
td.create_environment("test", display_name: "Test", uuid: "1234", contacts: [ { name: "Foo" } ] )
|
6
|
+
end
|
7
|
+
let(:path) { PactBroker::Api::PactBrokerUrls.environment_url(td.and_return(:environment)) }
|
8
|
+
let(:headers) { {'HTTP_ACCEPT' => 'application/hal+json'} }
|
9
|
+
let(:response_body) { JSON.parse(subject.body, symbolize_names: true)}
|
10
|
+
|
11
|
+
subject { get(path, nil, headers) }
|
12
|
+
|
13
|
+
it { is_expected.to be_a_hal_json_success_response }
|
14
|
+
|
15
|
+
it "returns the environment" do
|
16
|
+
expect(response_body[:uuid]).to eq "1234"
|
17
|
+
expect(response_body[:name]).to eq "test"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'pact_broker/api/pact_broker_urls'
|
2
|
+
|
3
|
+
describe "Get all environments" do
|
4
|
+
before do
|
5
|
+
td.create_environment("test", display_name: "Test", uuid: "1234", contacts: [ { name: "Foo" } ] )
|
6
|
+
.create_environment("prod", display_name: "Production", uuid: "5678", contacts: [ { name: "Foo" } ] )
|
7
|
+
end
|
8
|
+
let(:path) { PactBroker::Api::PactBrokerUrls.environments_url }
|
9
|
+
let(:headers) { {'HTTP_ACCEPT' => 'application/hal+json'} }
|
10
|
+
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
|
11
|
+
|
12
|
+
subject { get(path, nil, headers) }
|
13
|
+
|
14
|
+
it { is_expected.to be_a_hal_json_success_response }
|
15
|
+
|
16
|
+
it "returns the environments" do
|
17
|
+
subject
|
18
|
+
expect(response_body[:_embedded][:environments].size).to be 2
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# pact-broker record-deployment --pacticipant Foo --version 1 --environment test --end-previous-deployment
|
3
|
+
#
|
4
|
+
|
5
|
+
describe "Record deployment", skip: "Not yet implemented" do
|
6
|
+
before do
|
7
|
+
td.create_environment("test")
|
8
|
+
.create_pacticipant("Foo")
|
9
|
+
.create_pacticipant_version("1")
|
10
|
+
end
|
11
|
+
let(:path) { "/pacticipants/Foo/versions/1/deployments/test" }
|
12
|
+
let(:headers) { {"CONTENT_TYPE" => "application/json"} }
|
13
|
+
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
|
14
|
+
|
15
|
+
subject { post(path, nil, headers) }
|
16
|
+
|
17
|
+
it { is_expected.to be_a_hal_json_created_response }
|
18
|
+
|
19
|
+
it "returns the Location header" do
|
20
|
+
subject
|
21
|
+
expect(last_response.headers["Location"]).to eq "http://example.org/deployments/123456"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the newly created deployment" do
|
25
|
+
subject
|
26
|
+
expect(response_body).to include_key(:createdAt)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'pact_broker/api/pact_broker_urls'
|
2
|
+
|
3
|
+
describe "Updating an environment" do
|
4
|
+
before do
|
5
|
+
td.create_environment("test", uuid: "1234", contacts: [ { name: "Foo" } ] )
|
6
|
+
end
|
7
|
+
let(:path) { PactBroker::Api::PactBrokerUrls.environment_url(td.and_return(:environment)) }
|
8
|
+
let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
|
9
|
+
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
|
10
|
+
let(:environment_hash) do
|
11
|
+
{
|
12
|
+
name: "test",
|
13
|
+
production: false,
|
14
|
+
displayName: "Testing"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { put(path, environment_hash.to_json, headers) }
|
19
|
+
|
20
|
+
it { is_expected.to be_a_hal_json_success_response }
|
21
|
+
|
22
|
+
it "returns the updated environment" do
|
23
|
+
subject
|
24
|
+
expect(response_body[:displayName]).to eq "Testing"
|
25
|
+
expect(response_body[:contacts]).to be nil
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the environment doesn't exist" do
|
29
|
+
let(:path) { "/environments/5678" }
|
30
|
+
|
31
|
+
it "returns a 404" do
|
32
|
+
expect(subject.status).to eq 404
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with invalid params" do
|
37
|
+
let(:environment_hash) { {} }
|
38
|
+
|
39
|
+
it "returns a 400 response" do
|
40
|
+
expect(subject.status).to be 400
|
41
|
+
expect(response_body[:errors]).to_not be nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|