Skip to content

Commit

Permalink
Fix for emtpy defaults section #204 (#212)
Browse files Browse the repository at this point in the history
Merging hiera's defaults did not work when `defaults` was
given in `hiera.yaml`, but empty (== `nil`).
  • Loading branch information
oneiros authored Nov 2, 2023
1 parent b69d7d6 commit 6198d21
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/hiera_data/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def load_content
else
{}
end
config['defaults'] ||= {}
defaults.deep_merge(config)
rescue => error
raise Hdm::Error, error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 5
defaults:
hierarchy:
- name: "common settings"
paths:
- "common.yaml"
1 change: 1 addition & 0 deletions test/models/environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class EnvironmentTest < ActiveSupport::TestCase
expected_environments = %w(
development
dynamic_datadir
empty_defaults
eyaml
globs
hdm
Expand Down
12 changes: 12 additions & 0 deletions test/models/hiera_data/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@ def base_path
Pathname.new(Rails.configuration.hdm["config_dir"]).join("environments", "multiple_hierarchies")
end
end

class HieraData::ConfigWithEmptyDefaultsTest < ActiveSupport::TestCase
test "empty defaults get replaced" do
config = HieraData::Config.new(base_path)
assert_not_nil config.content["defaults"]
assert_equal Puppet::Pops::Lookup::HieraConfigV5::DEFAULT_CONFIG_HASH["defaults"], config.content["defaults"]
end

def base_path
Pathname.new(Rails.configuration.hdm["config_dir"]).join("environments", "empty_defaults")
end
end
end

0 comments on commit 6198d21

Please sign in to comment.