Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolate variables in datadir used for globs #329 #333

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/hiera_data/hierarchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def resolved_paths(facts:)
resolved_path = Interpolation.interpolate_facts(path:, facts:)
if uses_globs?
resolved_path = Interpolation
.interpolate_globs(path: resolved_path, datadir:)
.interpolate_globs(path: resolved_path, datadir: datadir(facts:))
end
resolved_path
end
Expand Down
12 changes: 12 additions & 0 deletions test/models/hiera_data/hierarchy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ class HierarchyTest < ActiveSupport::TestCase
assert_equal expected_resolved_paths, hierarchy.resolved_paths(facts:)
end

test "#resolved_paths resolves globs when given a dynamic datadir" do
base_path = Rails.root.join("test/fixtures/files/puppet/environments/dynamic_datadir")
globs = ["c*.yaml"]
raw_hash = { "name" => "Common", "datadir" => "%{facts.custom.datadir}", "globs" => globs }
hierarchy = HieraData::Hierarchy.new(raw_hash:, base_path:)
facts = { "custom" => { "datadir" => "data1" } }
expected_resolved_paths = [
"common.yaml"
]
assert_equal expected_resolved_paths, hierarchy.resolved_paths(facts:)
end

test "#name returns the existing name" do
hierarchy = HieraData::Hierarchy.new(raw_hash:, base_path: ".")
assert_equal "Yaml hierarchy", hierarchy.name
Expand Down