Skip to content

Commit

Permalink
feat(wip pacts): experimental feature - if no provider versions exist…
Browse files Browse the repository at this point in the history
…, consider all head pacts wip

To enable this feature, set PACT_BROKER_FEATURES=experimental_no_provider_versions_makes_all_head_pacts_wip
  • Loading branch information
bethesque committed Nov 25, 2020
1 parent 8b2a8cf commit a635cc5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'pact_broker/pacts/selected_pact'
require 'pact_broker/pacts/selector'
require 'pact_broker/pacts/selectors'
require 'pact_broker/feature_toggle'

module PactBroker
module Pacts
Expand Down Expand Up @@ -214,14 +215,15 @@ def find_wip_pact_versions_for_provider provider_name, provider_tags_names = [],
.where(name: provider_tags_names)
.all

wip_pacts.collect do | pact|
provider_version_count = scope_for(PactBroker::Domain::Version).where(pacticipant: provider).count

wip_pacts.collect do | pact|
pending_tag_names = find_provider_tags_for_which_pact_publication_id_is_pending(pact, successfully_verified_head_pact_publication_ids_for_each_provider_tag)
pre_existing_tag_names = find_provider_tag_names_that_were_first_used_before_pact_published(pact, provider_tag_collection)

pre_existing_pending_tags = pending_tag_names & pre_existing_tag_names

if pre_existing_pending_tags.any?
if pre_existing_pending_tags.any? || (PactBroker.feature_enabled?(:experimental_no_provider_versions_makes_all_head_pacts_wip) && provider_version_count == 0)
selectors = Selectors.create_for_latest_of_each_tag(pact.head_tag_names)
VerifiablePact.new(pact.to_domain, selectors, true, pre_existing_pending_tags, [], true)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,30 @@ module Pacts
end
end

context "when the provider tag does not exist yet" do
context "when the provider tag does not exist yet and there are no provider versions" do
before do
td.create_pact_with_hierarchy("foo", "1", "bar")
.create_consumer_version_tag("feat-x")
end

it "is included" do
expect(subject.size).to be 1
end
end

context "when the provider tag does not exist yet but there are other provider versions" do
before do
td.create_pact_with_hierarchy("foo", "1", "bar")
.create_consumer_version_tag("feat-x")
.create_provider_version("1")
end

it "doesn't return any pacts" do
expect(subject.size).to be 0
end
end


context "when a pact was published between the first creation date of two provider tags" do
let(:provider_tags) { %w[dev feat-1] }

Expand Down

0 comments on commit a635cc5

Please sign in to comment.