Skip to content

Commit

Permalink
Interpolate variables in datadir used for globs #329
Browse files Browse the repository at this point in the history
  • Loading branch information
oneiros committed Mar 21, 2024
1 parent bc6f9c0 commit f4c09d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit f4c09d2

Please sign in to comment.