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 215 forks source link

Verifying pacts from a specific consumer when verifying with the broker. #227

Closed ertrzyiks closed 3 years ago

ertrzyiks commented 3 years ago

Hey, here is more or less configuration we use to verify provider against consumers.

Pact.service_provider(provider) do
  app_version(version)
  app_version_tags(tags)

  honours_pacts_from_pact_broker do
    pact_broker_base_url ...
    consumer_version_selectors [
      { tag: 'production', fallback_tag: 'master', latest: true }
    ]
    include_wip_pacts_since '2020-10-28'
    enable_pending true
  end
end

How can I filter the consumers? Assume the broker includes information about consumers A, B, C. How can I ask broker for pacts related to consumer A only? Is it possible to have something like that:

consumer_version_selectors [
  { name: 'A', tag: 'production', fallback_tag: 'master', latest: true }
 ]
bethesque commented 3 years ago

See the docs: https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors#properties

ertrzyiks commented 3 years ago

@bethesque is it possible to filter out consumer for WIP too? I followed the documentation and ended up with configuration similar to

honours_pacts_from_pact_broker do
  pact_broker_base_url  ...

  consumer_version_selectors [
    {consumer: 'My Consumer', tag: 'production', latest: true}
  ]

  include_wip_pacts_since '2020-12-01'
  enable_pending true
end

It fetches WIP contracts also for other consumers than My Consumer. Is there any way to narrow WIP selection down too?

bethesque commented 3 years ago

No, sorry, it hadn't occurred to me. You can raise a feature request for it at https://pact.canny.io. I had wondered about configuring the wip pacts in the selectors. eg.

consumer_version_selectors [
     {consumer: 'My Consumer', tag: 'production', latest: true }, { wip: true, since: "2020-12-01" }
  ]

That would allow us to do:

consumer_version_selectors [
     {consumer: 'My Consumer', tag: 'production', latest: true }, { wip: true, since: "2020-12-01", consumer: 'My Consumer' }
  ]

But technically, the selectors select the consumer versions not the pacts, and "wip" applies to a pact not a consumer version, so it should be:

consumer_version_selectors [
     {consumer: 'My Consumer', tag: 'production', latest: true }
  ]

wip_pacts_selectors [
  { since: "2020-12-01", consumer: 'My Consumer' }
]
ertrzyiks commented 3 years ago

Got it, thank you! I created a post