forked from YOU54F/pact-ruby-ffi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpactffi_verifier_spec.rb
45 lines (45 loc) · 1.45 KB
/
pactffi_verifier_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'net/http'
require 'uri'
require 'webrick'
require 'pact/ffi/verifier'
require 'pact/ffi/logger'
require 'json'
PactFfi::Logger.log_to_stdout(PactFfi::Logger::LogLevel['INFO'])
RSpec.describe 'pactffi verifier spec' do
before(:all) do
# running in process, results in requests only hitting server when verification complete
@pid = Process.spawn('ruby provider.rb')
puts @pid
# Check server is up
uri = URI.parse('http://localhost:8000/api/books')
response = nil
100.times do # long sleep due to delays under qemu in ci
response = Net::HTTP.get_response(uri)
break if response.code == '404'
rescue Errno::ECONNREFUSED
sleep(1)
end
if response && response.code == '404'
puts 'Healthcheck passed'
else
puts 'Healthcheck failed'
end
end
after(:all) do
puts @pid
Process.kill('SIGKILL', @pid)
Process.wait(@pid)
end
let(:verifier) { PactFfi::Verifier.new_for_application('pact-ruby', '1.0.0') }
after do
PactFfi::Verifier.shutdown(verifier)
# @server_thread.kill
end
it 'should respond verify with pact' do
PactFfi::Verifier.set_provider_info(verifier, 'http-provider', 'http', nil, 8000, '/')
PactFfi::Verifier.add_file_source(verifier,
'pacts/http-consumer-1-http-provider.json')
result = PactFfi::Verifier.execute(verifier)
expect(result).to eq(PactFfi::Verifier::Response['VERIFICATION_SUCCESSFUL'])
end
end