From 0aca507f9bd2927edbfa1136fa3adc526d9a41b8 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Thu, 12 May 2016 21:55:29 +1000 Subject: [PATCH] Refactored to not use the Pact rake tasks. Traveling Ruby does not like shelling out to a Ruby process (where's my Gems?) --- examples/me-they.json | 2 +- examples/test.sh | 5 ++++- lib/pact/provider_verifier/app.rb | 33 +++++++++++++++++++++++-------- lib/pact/provider_verifier/cli.rb | 1 + packaging/wrapper.sh | 2 +- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/examples/me-they.json b/examples/me-they.json index 7fbbf6f..53293f0 100644 --- a/examples/me-they.json +++ b/examples/me-they.json @@ -32,7 +32,7 @@ "headers": { }, "body": { - "greeting": "Hello" + "greeting": "Oh yes!" } } }, diff --git a/examples/test.sh b/examples/test.sh index 9840a39..d573913 100755 --- a/examples/test.sh +++ b/examples/test.sh @@ -6,10 +6,13 @@ sleep 2 puts "=> Running Pact" res = `ruby -I../lib ../bin/pact-provider-verifier --provider-base-url http://localhost:4567 --pact-urls ./me-they.json --provider_states_setup_url http://localhost:4567/provider-state --provider_states_url http://localhost:4567/provider-states` + +# Test the actual gem +# res = `../pkg/pact-provider-verifier-0.0.2-1-osx/bin/pact-provider-verifier --provider-base-url http://localhost:4567 --pact-urls ./me-they.json --provider_states_setup_url http://localhost:4567/provider-state --provider_states_url http://localhost:4567/provider-states` code = $? puts "=> Shutting down API" Process.kill 'TERM', pipe.pid puts "#{res}" -exit code.to_i +exit code.exitstatus diff --git a/lib/pact/provider_verifier/app.rb b/lib/pact/provider_verifier/app.rb index b79181d..d34e9a6 100644 --- a/lib/pact/provider_verifier/app.rb +++ b/lib/pact/provider_verifier/app.rb @@ -36,16 +36,33 @@ def verify_pacts proxy_pact_helper = File.expand_path(File.join(File.dirname(__FILE__), "pact_helper.rb")) ENV['provider_states_url'] = @options.provider_states_url ENV['provider_states_setup_url'] = @options.provider_states_setup_url + provider_base_url = @options.provider_base_url - pacts.each do |pact_url| - Pact::ProxyVerificationTask.new :"#{pact_url}" do | task | - ENV['pact_consumer'] = get_pact_consumer_name(pact_url) - task.pact_url pact_url, :pact_helper => proxy_pact_helper - task.provider_base_url @options.provider_base_url + require 'pact/provider/rspec' + require 'rack/reverse_proxy' + + Pact.service_provider "Running Provider Application" do + app do + Rack::ReverseProxy.new do + reverse_proxy '/', provider_base_url end - task_name = "pact:verify:#{pact_url}" - Rake::Task[task_name].invoke - Rake::Task[task_name].reenable + end + end + + require ENV['PACT_PROJECT_PACT_HELPER'] if ENV.fetch('PACT_PROJECT_PACT_HELPER','') != '' + + exit_statuses = pacts.collect do |pact_url| + options = { + :pact_helper => proxy_pact_helper, + :pact_uri => pact_url, + :backtrace => false + } + require 'pact/cli/run_pact_verification' + Cli::RunPactVerification.call(options) + end + + Pact::Provider::Proxy::TaskHelper.handle_verification_failure do + exit_statuses.count{ | status | status != 0 } end end end diff --git a/lib/pact/provider_verifier/cli.rb b/lib/pact/provider_verifier/cli.rb index 50e6b3d..e4402aa 100644 --- a/lib/pact/provider_verifier/cli.rb +++ b/lib/pact/provider_verifier/cli.rb @@ -13,6 +13,7 @@ class CLI < Thor def verify app = Pact::ProviderVerifier::App.new(options) + app.verify_pacts end default_task :verify diff --git a/packaging/wrapper.sh b/packaging/wrapper.sh index 8aa4ba9..4157bab 100755 --- a/packaging/wrapper.sh +++ b/packaging/wrapper.sh @@ -22,4 +22,4 @@ export BUNDLE_GEMFILE="$LIBDIR/vendor/Gemfile" unset BUNDLE_IGNORE_CONFIG # Run the actual app using the bundled Ruby interpreter, with Bundler activated. -exec "$LIBDIR/ruby/bin/ruby" -rbundler/setup -I$LIBDIR/app/lib "$LIBDIR/app/pact-provider-verifier.rb" $@ +exec "$LIBDIR/ruby/bin/ruby" -rbundler/setup -rreadline -I$LIBDIR/app/lib "$LIBDIR/app/pact-provider-verifier.rb" $@