Closed victor-vineti closed 3 months ago
That's a good question. You must be the first person to try it. I don't think I considered this when I wrote it. I'll have to look into it for you.
You may have some other issues because there is limited support for applications that are both message and http pact consumers/providers. What language and pact specification are you using to generate your pacts?
We are using Ruby for the language.
I am not quite sure how to look up the specific Pact specification. Gemfile.lock gives these if this can be mapped to the Pact specification:
pact-message (0.11.1)
pact-mock_service (~> 3.1)
pact-support (~> 1.8)
thor (>= 0.20, < 2.0)
pact-mock_service (3.9.1)
filelock (~> 1.1)
find_a_port (~> 1.0.1)
json
pact-support (~> 1.16, >= 1.16.4)
rack (~> 2.0)
rspec (>= 2.14)
term-ansicolor (~> 1.0)
thor (>= 0.19, < 2.0)
webrick (~> 1.3)
pact-support (1.16.7)
awesome_print (~> 1.1)
diff-lcs (~> 1.4)
randexp (~> 0.1.7)
term-ansicolor (~> 1.0)
The site says this: Pactflow Version: c63147d72.
@bethesque is there an available workaround? We were thinking of having two pact_helper.rb
files, one for message pacts and one for http pacts, and separate verify commands for each as a potential workaround.
Hi Jason, yes there is a workaround. Make two separate pact_helper files, but make sure the second one isn't called "pact_helper.rb" or it will be automatically loaded.
Make a new pact verification task, and set the pact_helper file manually. Here are the docs for the custom task
https://docs.pact.io/implementation_guides/ruby/verifying_pacts#using-a-custom-pactverify-task
Pact::VerificationTask.new(:message) do | task |
task.pact_helper '/path/to/your/message/pact/helper'
end
This workaround worked! Thank you @bethesque, appreciate it.
If the consumer describes both HTTP and message based interactions for the provider, then running the custom pact verification task and the default one will both have pending failures because they are isolated to either HTTP or message. Does this mean I'll have to break out the consumer into two separate tests?
Before:
describe 'My Provider', pact: true do
context 'HTTP based interactions' do
...
end
context 'message based interactions' do
...
end
end
After:
describe 'My Provider HTTP', pact: true do
...
end
describe 'My Provider message', pact: true do
...
end
The spec tag for message pact is actually pact: :message
. Does that make a difference?
Sorry for the late follow up, but that didn't work for us. For now, we're splitting our HTTP and message interactions within a service.
Message pact was introduced in pact V3 specification. one of the limitations was that a pact file could not contain both http and message pact interactions.
You may have some other issues because there is limited support for applications that are both message and http pact consumers/providers.
Which means this is still an issue with the pact v3 spec.
Pact v4 spec introduced multiple interaction types in a single pact file, mitigating this limitation. This should be considered during #319.
For now, if you are using pact-message-ruby for consumers, or pact-ruby for verifying providers, name http/message providers differently, and create 1 distinct helpers and 2 verification tasks, 1 for each type (http & message).
A useful interim measure would be to have a warning if a user has configured both a service_provider and message_provider in the same file.
We're having an issue configuring a
Pact.service_provider
and aPact.message_provider
1. The relevant versions of the gems you are using.:
1. The steps to recreate your issue.
pact_helper.rb
in theservice_consumers
folderbundle exec rails pact:verify
Code example:
The issue is that Pact executes either the
service_provider
block correctly or themessage_provider
block in isolation but not both.If the
service_provider
block is above themessage_provider
it runs thebuilder do
block for the service provider. This produces this error:I don't see why the
service_provider
should run a builder function as that isn't part of its configuration.If the
message_provider
is ran before theservice_provider
, then this is the error.I think the issue is because of the inheritance and this line: https://github.com/pact-foundation/pact-ruby/blob/bb0ddca700f9aeb05c9f78d214cdbe2962a50786/lib/pact/provider/configuration/message_provider_dsl.rb#L52-L54.
How should we configure this for both http requests and message requests?