pact-foundation / pact-ruby

Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
2.17k stars 216 forks source link

Verifying pacts from a specific consumer. #193

Closed abhitrivedi closed 4 years ago

abhitrivedi commented 5 years ago

Hi.

I work with an app that has many consumers. We recently upgraded our pact-broker and I am currently setting up webhooks to verify pacts on contract_content_changed event. Im wondering is there a way for the provider to verify pacts from a specific consumer? Looking at the docs I see options for passing in a provider state or a specific interaction, but I couldn't find an option where one could specify "verify all interactions of consumer Foo".

bheemreddy181-zz commented 5 years ago

isn't by default all the interactions are verified if you don't specify a state?

abhitrivedi commented 5 years ago

Yes, if I specify a provider state then all related interactions are executed. However, Im looking for the ability to execute all interactions for a given consumer.

For instance, here is a sample provider config:

Pact.service_provider "MyService" do
  honours_pact_with "Foo" do
    ...
  end
  honours_pact_with "Bar" do
    ...
  end
  honours_pact_with "Baz" do
    ...
  end
end

What I am looking for is the ability to verify all interactions for a specific consumer, something like this:

bundle exec rake pact:verify CONSUMER=Foo
bethesque commented 5 years ago

Make a custom rake task, and give it the URL of the pact for just that consumer (making sure you use the "/latest" URL).

https://github.com/pact-foundation/pact-ruby/wiki/Verifying-pacts#using-a-custom-pactverify-task

This will use the app set up from your pact_helper but verify the pacts that you specify instead of the ones configured in the service_provider block.

bethesque commented 5 years ago

Oh, given you're verifying just the changed pact, use the webhook templating to pass the ${pactbroker.pactUrl} into the CI job, and then pass that URL into the custom rake task using an environment variable.

bethesque commented 5 years ago

https://github.com/pact-foundation/pact_broker/wiki/Webhooks#provider-ci