pact-provider-proxy and single pact verification

165 views
Skip to first unread message

André Allavena

unread,
Apr 20, 2015, 8:51:36 PM4/20/15
to pact-s...@googlegroups.com
Hello

I'm trying to verify one pact at a time, with pact provider proxy.
For some odd reason, I was stuck on older version of the gems, where I
had it working with the following:

puts "Checking Pact #{pact} on #{service}"
ENV['PACT_DESCRIPTION']=pact
Rake::Task["pact:verify:#{service}"].execute

This no longer works. It now verifies all pacts for each 'execute'.
I've seen some code changes in pact 1.5, but to me it was the inner
call that changed, user call is still using ENV. Is this a regression,
pact-proxy got left out? or a change in syntax?

I'm using this to force an order on the pact verification, across two
providers as that's the only way I have to load data on my two,
out-of-my-control coupled providers.

Older versions, where above code works
- pact (1.4.0)
- pact-mock_service (~> 0.2.0)
- pact-support (~> 0.1.2)
- pact-mock_service (0.2.3.pre.rc1)
- pact-support (~> 0.1.1)
- pact-support (0.1.4)
- pact-mock_service (= 0.2.3.pre.rc1)

New versions:
+ pact (1.7.0)
+ pact-mock_service (~> 0.5.0)
+ pact-support (~> 0.4.0)
+ pact-mock_service (0.5.1)
+ pact-support (~> 0.4.0)
+ pact-support (0.4.0)

Thanks
André

Bethany Skurrie

unread,
Apr 20, 2015, 10:11:18 PM4/20/15
to André Allavena, pact-s...@googlegroups.com
I'm a bit confused by the example. PACT_DESCRIPTION has only ever been a filter on the description of the interactions. The line:

ENV['PACT_DESCRIPTION']=pact

makes no sense in this context, unless every description in your pact file has the text of what ever value you've given "pact" in your code.

What does your provider proxy verify task look like?



André

--
You received this message because you are subscribed to the Google Groups "Pact" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pact-support...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Bethany Skurrie
Software Developer

DiUS Computing Pty. Ltd.
where ideas are engineered

Phone: +61 3 9008 5400
Mobile: +61 415 413 713

www.dius.com.au

This email is intended solely for the use of the addressee and may contain information that is confidential or privileged. If you receive this email in error please notify the sender and delete the email immediately.

André Allavena

unread,
Apr 20, 2015, 10:44:41 PM4/20/15
to Bethany Skurrie, pact-s...@googlegroups.com
I programmatically set the ENV value to each of the pact description I
want to verify before calling the verification task. So

# First pact to verify
ENV['PACT_DESCRIPTION'] = 'description_of_my_first_pact
Rake::Task["pact:verify:#{service}"].execute
# Second pact to verify
ENV['PACT_DESCRIPTION'] = 'description_of_my_second_pact
Rake::Task["pact:verify:#{service}"].execute
etc.


I'm relying on https://github.com/realestate-com-au/pact/wiki/Verifying-pacts,
which suggested using
$ rake pact:verify PACT_DESCRIPTION="a request for something"
PACT_PROVIDER_STATE="something exists"


My whole Rake task (which I'm happy to accept is a hack, I haven't
figured out a better way to do it)


desc('Run the provider integration tests, in the specified order, ')
task(:provider_verify_ordered) do
Rake::TestTask.new(:dummy_name) do
require 'pact/provider/proxy/tasks'
Pact::ProxyVerificationTask.new :userapi_service do | task |
task.pact_url
'./spec/pacts/userapi_service_consumer-userapi_service_provider.json'
task.provider_base_url 'https://userapi.****.com/'
end
Pact::ProxyVerificationTask.new :otherapi_service do | task |
task.pact_url
'./spec/pacts/otherapi_service_consumer-otherapi_service_provider.json'
task.provider_base_url 'https://otherapi.*****.com'
end

pacts_to_verify= [['registration
success','user'],['get_offer','other'],['issue offer','offer'],
['payment','user'],['get extra offers','other']]

pacts_to_verify.each{ |pact,s|
begin
service = (s == 'user' ? 'userapi_service' : 'otherapi_service')
puts "Checking Pact #{pact} on #{service}"
ENV['PACT_DESCRIPTION']=pact
Rake::Task["pact:verify:#{service}"].execute
rescue Exception => e
puts e.inspect
puts "Checking Pact #{pact} failed\n\n"
end
}

# Code that greps through the files to count how many pacts there are
to make sure I didn't miss any.


André

Bethany Skurrie

unread,
Apr 20, 2015, 11:18:26 PM4/20/15
to André Allavena, pact-s...@googlegroups.com
Firstly, I think when you say "pact", you mean "interaction". Interaction = request + response. Pact = many interactions. That's why I was confused!

Let me have a look at that, I'm sure there is a better way. 

Bethany Skurrie

unread,
Apr 21, 2015, 7:27:08 PM4/21/15
to André Allavena, pact-s...@googlegroups.com
I've pushed out a new version of pact-provider-proxy that will respect the PACT_DESCRIPTION and PACT_PROVIDER_STATE variables.

I've also had a go at simplifying the script here: https://gist.github.com/bethesque/08d4c4cca2e76653420b

André Allavena

unread,
Apr 21, 2015, 11:10:00 PM4/21/15
to Bethany Skurrie, pact-s...@googlegroups.com
Great thanks.

I can confirm this fixes the issue for me.

Thanks for the script clean up and rewrite. I had missed the tasks
were raising SystemExit when verification failed. I'll catch that and
continue (I prefer it that way with this provider, it shouldn't be
that way generally though)

André
Reply all
Reply to author
Forward
0 new messages