Skip to content

Commit

Permalink
chore: sort resolved selectors deterministically
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 11, 2021
1 parent b181974 commit 39129db
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/pacts/selected_pact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(pact, selectors)

def self.merge(selected_pacts)
latest_selected_pact = selected_pacts.sort_by(&:consumer_version_order).last
selectors = selected_pacts.collect(&:selectors).reduce(&:+)
selectors = selected_pacts.collect(&:selectors).reduce(&:+).sort
SelectedPact.new(latest_selected_pact.pact, selectors)
end

Expand Down
9 changes: 9 additions & 0 deletions lib/pact_broker/pacts/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ def environment
def == other
super && consumer_version == other.consumer_version
end

def <=> other
comparison = super
if comparison == 0
consumer_version.order <=> other.consumer_version.order
else
comparison
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/pact_broker/pacts/selectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def + other
Selectors.new(super)
end

def sort
Selectors.new(super)
end

def overall_latest?
any?(&:overall_latest?)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Pacts
provider_branch: provider_branch
)
end
let(:consumer_version) { double("version", number: "1234" )}
let(:consumer_version) { double("version", number: "1234", order: 1) }
let(:environment) { instance_double("PactBroker::Deployments::Environment", name: "test") }
let(:test_environment) { environment }
let(:prod_environment) { instance_double("PactBroker::Deployments::Environment", name: "prod") }
Expand Down

0 comments on commit 39129db

Please sign in to comment.