Skip to content

Commit

Permalink
test(win): enable windows tests
Browse files Browse the repository at this point in the history
- require taskkill to ensure processes are killed when running test suite locally
- required binstub for cmd prompt, if ran from powershell or cmd prompt for prev skipped tests
  • Loading branch information
YOU54F committed Aug 13, 2024
1 parent d9a3c90 commit ad41e11
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 35 deletions.
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
20 changes: 14 additions & 6 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
puts 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 ad41e11

Please sign in to comment.