Skip to content

Commit

Permalink
Merge pull request #141 from betadots/issue-108
Browse files Browse the repository at this point in the history
Deep merge hiera defaults #108
  • Loading branch information
rwaffen authored Feb 10, 2023
2 parents 3bd03bb + 8b494b7 commit e0e4d63
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/hiera_data/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def load_content
else
{}
end
defaults.merge(config)
defaults.deep_merge(config)
rescue => error
raise Hdm::Error, error
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/hiera_data/hierarchy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class HieraData
class Hierarchy
LOOKUP_FUNCTIONS = %w(data_hash lookup_key data_dig hiera3_backend).freeze
LOOKUP_FUNCTIONS = %w(lookup_key data_hash data_dig hiera3_backend).freeze
attr_reader :raw_hash

def initialize(raw_hash:, base_path:)
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/files/puppet/environments/no_datadir/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
version: 5

defaults:
lookup_key: eyaml_lookup_key
1 change: 1 addition & 0 deletions test/models/environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class EnvironmentTest < ActiveSupport::TestCase
minimal
multiple_hierarchies
no_config
no_datadir
test
v3
)
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 @@ -34,6 +34,18 @@ def base_path
end
end

class HieraData::ConfigNoDatadirInYamlFile < ActiveSupport::TestCase
test "uses default datadir from puppet" do
config = HieraData::Config.new(base_path)
assert_not_nil config.content["defaults"]
assert_equal Puppet::Pops::Lookup::HieraConfigV5::DEFAULT_CONFIG_HASH["defaults"]["datadir"], config.content["defaults"]["datadir"]
end

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

class HieraData::ConfigWithSomeHierarchiesTest < ActiveSupport::TestCase
test "when only defaults, return the yaml paths" do
config = HieraData::Config.new(base_path)
Expand Down

0 comments on commit e0e4d63

Please sign in to comment.