Skip to content

Commit

Permalink
Merge pull request #126 from pact-foundation/feat/windows_binstubs
Browse files Browse the repository at this point in the history
Feat/windows binstubs
  • Loading branch information
YOU54F authored Aug 14, 2024
2 parents 041a091 + ee4d44c commit b024db9
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 34 deletions.
30 changes: 30 additions & 0 deletions bin/pact-provider-verifier.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@ruby -x "%~f0" %*
@exit /b %ERRORLEVEL%

#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'pact-provider-verifier' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("pact-provider-verifier", "pact-provider-verifier")
6 changes: 5 additions & 1 deletion examples/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ res = `pact-provider-verifier --provider-base-url http://localhost:4567 --pact-u
puts res

puts "=> Shutting down API"
Process.kill 'TERM', pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'TERM', pipe.pid
end

puts "Test exit status: #{res}"
puts
8 changes: 6 additions & 2 deletions spec/integration_check_host_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe "pact-provider-verifier", skip_windows: true do
describe "pact-provider-verifier" do
before(:all) do
@pipe = IO.popen("bundle exec rackup -p 4569 spec/support/provider-echo-host.ru")
sleep 2
Expand All @@ -11,6 +11,10 @@
end

after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
18 changes: 13 additions & 5 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'json'
require 'fileutils'

describe "pact-provider-verifier", skip_windows: true do
describe "pact-provider-verifier" do
before(:all) do
@pipe = IO.popen("bundle exec rackup -p 4567 spec/support/config.ru")
sleep 2
Expand Down Expand Up @@ -77,15 +77,19 @@
end

context "running verification with filtered interactions" do

subject { `PACT_DESCRIPTION="Provider state success" PACT_PROVIDER_STATE="There is a greeting" bundle exec bin/pact-provider-verifier ./test/me-they.json -a 1.0.100 --provider-base-url http://localhost:4567 --provider-states-setup-url http://localhost:4567/provider-state -v` }
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
env_vars = 'set PACT_DESCRIPTION="Provider state success" && set PACT_PROVIDER_STATE="There is a greeting" && '
else
env_vars = 'PACT_DESCRIPTION="Provider state success" PACT_PROVIDER_STATE="There is a greeting" '
end
subject { `#{env_vars}bundle exec bin/pact-provider-verifier ./test/me-they.json -a 1.0.100 --provider-base-url http://localhost:4567 --provider-states-setup-url http://localhost:4567/provider-state -v` }

it "exits with a 0 exit code" do
subject
expect($?).to eq 0
end

it "the output contains a message indicating that the interactions have been filtered" do
it "the output contains a message indicating that the interactions have been filtered", skip_windows: true do
expect(subject).to match /Filtering interactions by.*Provider state success.*There is a greeting/
end
end
Expand Down Expand Up @@ -148,6 +152,10 @@
end

after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
8 changes: 6 additions & 2 deletions spec/integration_verify_message_pact_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'pact/provider_verifier/app'

RSpec.describe "verifying a message pact", skip_windows: true do
RSpec.describe "verifying a message pact" do

before(:all) do
@pipe = IO.popen("rackup -p 9393 spec/support/message_producer_verifier.ru")
Expand All @@ -26,6 +26,10 @@
end

after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
8 changes: 6 additions & 2 deletions spec/integration_with_custom_header_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe "pact-provider-verifier with basic auth", skip_windows: true do
describe "pact-provider-verifier with basic auth" do
before(:all) do
@pipe = IO.popen({'USE_BASIC_AUTH' => 'true'}, %w{bundle exec rackup -p 4570 spec/support/config.ru})
sleep 2
Expand All @@ -25,6 +25,10 @@
end

after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
8 changes: 6 additions & 2 deletions spec/integration_with_custom_middleware_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe "pact-provider-verifier with basic auth", skip_windows: true do
describe "pact-provider-verifier with basic auth" do
before(:all) do
@pipe = IO.popen({'USE_BASIC_AUTH' => 'true'}, %w{bundle exec rackup -p 4570 spec/support/config.ru})
sleep 2
Expand All @@ -22,6 +22,10 @@
end

after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
8 changes: 6 additions & 2 deletions spec/integration_with_monkeypatch_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe "pact-provider-verifier with monkeypatch", skip_windows: true do
describe "pact-provider-verifier with monkeypatch" do
before(:all) do
@pipe = IO.popen({}, %w{bundle exec rackup -p 4870 spec/support/config.ru})
sleep 2
Expand All @@ -19,6 +19,10 @@


after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
8 changes: 6 additions & 2 deletions spec/integration_with_prefix_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'json'

describe "pact-provider-verifier with a prefix path in the base URL", skip_windows: true do
describe "pact-provider-verifier with a prefix path in the base URL" do
before(:all) do
@pipe = IO.popen("bundle exec rackup -p 5837 spec/support/config_with_prefix.ru")
sleep 2
Expand All @@ -18,6 +18,10 @@
end

after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
25 changes: 14 additions & 11 deletions spec/integration_with_ssl_no_verify_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
require 'support/provider_with_self_signed_cert'
require 'find_a_port'

describe "verifying a provider that uses a self signed certificate", skip_windows: true do
describe "verifying a provider that uses a self signed certificate" do

before(:all) do
@port = FindAPort.available_port
@pipe = IO.popen({}, %W{ruby spec/support/provider_with_self_signed_cert.rb #{@port}})
sleep 2
end
it "passes because it has SSL verification turned off" do
begin
@port = FindAPort.available_port
@ssl_server_pid = fork do
run_provider_with_self_signed_cert @port
end
sleep 2
subject = `bundle exec bin/pact-provider-verifier ./test/me-they.json -a 1.0.0 --provider-base-url https://localhost:#{@port} --provider_states_setup_url https://localhost:#{@port}/provider-state -v`
expect(subject).to include "2 interactions, 0 failures"
ensure
Process.kill('KILL', @ssl_server_pid)
subject = `bundle exec bin/pact-provider-verifier ./test/me-they.json -a 1.0.0 --provider-base-url https://localhost:#{@port} --provider_states_setup_url https://localhost:#{@port}/provider-state -v`
expect(subject).to include "2 interactions, 0 failures"
end
after(:all) do
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
8 changes: 6 additions & 2 deletions spec/integration_with_underscored_header_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'find_a_port'

describe "pact-provider-verifier with an underscored header", skip_windows: true do
describe "pact-provider-verifier with an underscored header" do
before(:all) do
@port = FindAPort.available_port
@pipe = IO.popen({}, %W{ruby spec/support/provider_with_no_rack.rb #{@port}})
Expand All @@ -16,6 +16,10 @@
end

after(:all) do
Process.kill 'KILL', @pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{@pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'KILL', @pipe.pid
end
end
end
5 changes: 3 additions & 2 deletions spec/support/provider_with_self_signed_cert.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative 'provider'

def run_provider_with_self_signed_cert port
trap 'INT' do @server.shutdown end
# trap 'INT' do @server.shutdown end
require 'rack'
require 'rack/handler/webrick'
require 'webrick/https'
Expand All @@ -21,5 +21,6 @@ def run_provider_with_self_signed_cert port
end

if __FILE__== $0
run_provider_with_self_signed_cert 4568
port = ARGV[0] ? ARGV[0].to_i : 4568
run_provider_with_self_signed_cert port
end
6 changes: 5 additions & 1 deletion test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ puts res
code = $?

puts "=> Shutting down API"
Process.kill 'TERM', pipe.pid
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system("taskkill /im #{pipe.pid} /f /t >nul 2>&1")
else
Process.kill 'TERM', pipe.pid
end

puts
puts
Expand Down

0 comments on commit b024db9

Please sign in to comment.