Skip to content

Commit

Permalink
feat: include environment name in pact metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 4, 2023
1 parent 7c36ebf commit e120c4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/pact_broker/pacts/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Metadata
[:consumer_version_selectors, "s"],
[:tag, "t"],
[:branch, "b"],
[:environment, "e"],
[:latest, "l"]
]

Expand Down Expand Up @@ -60,13 +61,13 @@ def build_metadata_for_pact_for_verification(verifiable_pact)
"w" => true
}
else
# TODO support deployed and released
{
"s" => verifiable_pact.selectors.collect do | selector |
{
"b" => selector.branch,
"t" => selector.tag,
"l" => selector.latest,
"e" => selector.environment_name,
"cv" => selector.consumer_version.id
}.compact
end,
Expand Down
21 changes: 18 additions & 3 deletions spec/lib/pact_broker/pacts/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ module Metadata

it { is_expected.to include "p" => true }
end

context "when the selector was deployed" do
let(:selectors) do
Selectors.new([ResolvedSelector.new({ environment_name: "prod" }, consumer_version)])
end

its(["s"]) { is_expected.to include_hash_matching "e" => "prod" }
end
end

describe "parse_metadata" do
Expand All @@ -47,6 +55,7 @@ module Metadata

let(:consumer_version) { double("version", number: "2", id: 1) }

# Not an actual possible selector, just avoiding writing more tests
let(:incoming_metadata) do
{
"cv" => 1,
Expand All @@ -56,7 +65,9 @@ module Metadata
{
"l" => true,
"t" => "tag",
"cv" => 1
"cv" => 1,
"e" => "prod",
"b" => "main"
}
],
"p" => true
Expand All @@ -73,7 +84,9 @@ module Metadata
{
:latest => true,
:tag => "tag",
:consumer_version_number => "2"
:consumer_version_number => "2",
:environment => "prod",
:branch => "main"
}
]
}
Expand All @@ -96,7 +109,9 @@ module Metadata
{
:latest => true,
:tag => "tag",
:consumer_version_number => nil
:consumer_version_number => nil,
:environment => "prod",
:branch => "main"
}
]
}
Expand Down

0 comments on commit e120c4e

Please sign in to comment.