From 68bd9eae73b7368bf25b61eb3c8061d441feb5ee Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 21 Jan 2021 11:00:24 +1100 Subject: [PATCH] chore: update issue reproduction code [ci-skip] --- ISSUES.md | 6 ++-- ...ue-repro-with-pact-broker-docker-image.yml | 33 +++++++++++++++++++ .../test/http_test_data_builder.rb | 2 +- script/reproduce-issue.rb | 31 +++++++++-------- 4 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 docker-compose-issue-repro-with-pact-broker-docker-image.yml diff --git a/ISSUES.md b/ISSUES.md index e7dd7ac99..db1e3f0ec 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -8,16 +8,16 @@ You can use it to easily reproduce issues. To use it: -* Run the Pact Broker using the latest development code: +* Run the Pact Broker using a specific Pact Broker Docker image by setting the required tag for the pact-broker service in the docker-compose-issue-repro-with-pact-broker-docker-image.yml file. ``` - docker-compose -f docker-compose-issue-repro.yml up --build pact-broker + docker-compose -f docker-compose-issue-repro-with-pact-broker-docker-image.yml up --build pact-broker ``` * Run the reproduction script. ``` - docker-compose -f docker-compose-issue-repro.yml up repro-issue + docker-compose -f docker-compose-issue-repro-with-pact-broker-docker-image.yml up repro-issue ``` You can modify `script/reproduce-issue.rb` and then re-run it with the change applied. diff --git a/docker-compose-issue-repro-with-pact-broker-docker-image.yml b/docker-compose-issue-repro-with-pact-broker-docker-image.yml new file mode 100644 index 000000000..1081ad41c --- /dev/null +++ b/docker-compose-issue-repro-with-pact-broker-docker-image.yml @@ -0,0 +1,33 @@ +version: "3" + +services: + postgres: + image: postgres + healthcheck: + test: psql postgres --command "select 1" -U postgres + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: postgres + + pact-broker: + image: pactfoundation/pact-broker:2.73.0.0 + ports: + - "9292:9292" + depends_on: + - postgres + environment: + PACT_BROKER_PORT: '9292' + PACT_BROKER_DATABASE_URL: "postgres://postgres:password@postgres/postgres" + PACT_BROKER_LOG_LEVEL: INFO + PACT_BROKER_SQL_LOG_LEVEL: DEBUG + + repro-issue: + build: . + depends_on: + - pact-broker + command: dockerize -wait http://pact-broker:9292 -timeout 30s /home/script/reproduce-issue.rb + environment: + - PACT_BROKER_BASE_URL=http://pact-broker:9292 + volumes: + - $PWD:/home diff --git a/lib/pact_broker/test/http_test_data_builder.rb b/lib/pact_broker/test/http_test_data_builder.rb index b973f8925..9112dafa5 100644 --- a/lib/pact_broker/test/http_test_data_builder.rb +++ b/lib/pact_broker/test/http_test_data_builder.rb @@ -10,7 +10,7 @@ class HttpTestDataBuilder attr_reader :client, :last_consumer_name, :last_provider_name, :last_consumer_version_number, :last_provider_version_number - def initialize(pact_broker_base_url, auth) + def initialize(pact_broker_base_url, auth = {}) @client = Faraday.new(url: pact_broker_base_url) do |faraday| faraday.request :json faraday.response :json, :content_type => /\bjson$/ diff --git a/script/reproduce-issue.rb b/script/reproduce-issue.rb index 96cfdde7a..ff1f181d9 100755 --- a/script/reproduce-issue.rb +++ b/script/reproduce-issue.rb @@ -1,28 +1,31 @@ #!/usr/bin/env ruby - -$LOAD_PATH << "#{Dir.pwd}/lib" - begin + $LOAD_PATH << "#{Dir.pwd}/lib" require 'pact_broker/test/http_test_data_builder' base_url = ENV['PACT_BROKER_BASE_URL'] || 'http://localhost:9292' - td = PactBroker::Test::HttpTestDataBuilder.new(base_url, { }) - td.delete_integration(consumer: "MyConsumer", provider: "MyProvider") - .create_pacticipant("MyConsumer") - .create_pacticipant("MyProvider") - .publish_pact(consumer: "MyConsumer", consumer_version: "1", provider: "MyProvider", content_id: "111", tag: "main") - .publish_pact(consumer: "MyConsumer", consumer_version: "2", provider: "MyProvider", content_id: "222", tag: "main") - .publish_pact(consumer: "MyConsumer", consumer_version: "3", provider: "MyProvider", content_id: "111", tag: "feat/a") + td = PactBroker::Test::HttpTestDataBuilder.new(base_url) + td.delete_integration(consumer: "foo-consumer", provider: "bar-provider") + .publish_pact(consumer: "foo-consumer", consumer_version: "1", provider: "bar-provider", content_id: "111", tag: "main") .get_pacts_for_verification( + enable_pending: true, provider_version_tag: "main", - consumer_version_selectors: [{ tag: "main" }, { tag: "feat/a", latest: true }]) - .verify_pact(success: true, provider_version_tag: "main", provider_version: "2" ) - + include_wip_pacts_since: "2020-01-01", + consumer_version_selectors: [{ tag: "main", latest: true }]) + .verify_pact( + index: 0, + provider_version_tag: "main", + provider_version: "1", + success: true + ) + .can_i_deploy(pacticipant: "bar-provider", version: "1", to: "prod") + .deploy_to_prod(pacticipant: "bar-provider", version: "1") + .can_i_deploy(pacticipant: "foo-consumer", version: "1", to: "prod") + .deploy_to_prod(pacticipant: "foo-consumer", version: "1") rescue StandardError => e puts "#{e.class} #{e.message}" puts e.backtrace exit 1 end -