From bf5e753da0bde6b6e494b3fd114a48b5643f7af4 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 13 Nov 2017 20:47:00 +1100 Subject: [PATCH] test: update rake task --- spec/support/bar_fail_pact_helper.rb | 2 +- tasks/foo-bar.rake | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/spec/support/bar_fail_pact_helper.rb b/spec/support/bar_fail_pact_helper.rb index 3917ef47..c5008443 100644 --- a/spec/support/bar_fail_pact_helper.rb +++ b/spec/support/bar_fail_pact_helper.rb @@ -5,7 +5,7 @@ module Pact module Test class BarApp def call env - [200, {'Content-Type' => 'application/json'}, [].to_json] + [200, {'Content-Type' => 'application/json'}, [{}].to_json] end end diff --git a/tasks/foo-bar.rake b/tasks/foo-bar.rake index d6fc8385..53633f37 100644 --- a/tasks/foo-bar.rake +++ b/tasks/foo-bar.rake @@ -2,6 +2,9 @@ require 'pact/tasks/verification_task' # Use for end to end manual debugging of issues. BROKER_BASE_URL = 'http://localhost:9292' +#BROKER_BASE_URL = 'https://test.pact.dius.com.au' +BROKER_USERNAME = ENV['PACT_BROKER_USERNAME'] +BROKER_PASSWORD = ENV['PACT_BROKER_PASSWORD'] RSpec::Core::RakeTask.new('pact:foobar:create') do | task | task.pattern = "spec/features/foo_bar_spec.rb" @@ -14,11 +17,11 @@ task 'pact:foobar:publish' do put_request = Net::HTTP::Put.new(uri.path) put_request['Content-Type'] = "application/json" put_request.body = File.read("spec/pacts/foo-bar.json") - response = Net::HTTP.start(uri.hostname, uri.port) do |http| + put_request.basic_auth(BROKER_USERNAME, BROKER_PASSWORD) if BROKER_USERNAME + response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: BROKER_BASE_URL.start_with?('https')) do |http| http.request put_request end puts response.code unless response.code == '200' - puts response.body end Pact::VerificationTask.new('foobar') do | pact | @@ -27,11 +30,11 @@ end Pact::VerificationTask.new(:foobar_using_broker) do | pact | - pact.uri "#{BROKER_BASE_URL}/pacts/provider/Bar/consumer/Foo/version/1.0.0", :pact_helper => './spec/support/bar_pact_helper.rb' + pact.uri "#{BROKER_BASE_URL}/pacts/provider/Bar/consumer/Foo/version/1.0.0", :pact_helper => './spec/support/bar_pact_helper.rb', username: BROKER_USERNAME, password: BROKER_PASSWORD end Pact::VerificationTask.new('foobar_using_broker:fail') do | pact | - pact.uri "#{BROKER_BASE_URL}/pacts/provider/Bar/consumer/Foo/version/1.0.0", :pact_helper => './spec/support/bar_fail_pact_helper.rb' + pact.uri "#{BROKER_BASE_URL}/pacts/provider/Bar/consumer/Foo/version/1.0.0", :pact_helper => './spec/support/bar_fail_pact_helper.rb', username: BROKER_USERNAME, password: BROKER_PASSWORD end task 'pact:verify:foobar' => ['pact:foobar:create']