diff --git a/app/controllers/lookups_controller.rb b/app/controllers/lookups_controller.rb index 66dbacd5..31220e68 100644 --- a/app/controllers/lookups_controller.rb +++ b/app/controllers/lookups_controller.rb @@ -5,8 +5,8 @@ class LookupsController < ApplicationController def show @result = @key.lookup(@node) - rescue Hdm::Error => error - @error = error + rescue Hdm::Error => e + @error = e render action: "error" end diff --git a/app/models/hiera_data/lookup.rb b/app/models/hiera_data/lookup.rb index 6be870ef..3b06613e 100644 --- a/app/models/hiera_data/lookup.rb +++ b/app/models/hiera_data/lookup.rb @@ -51,7 +51,6 @@ def flat_hash_merge(values) def deep_merge(values) values.inject do |memo, value| memo ||= {} - raise Hdm::Error, "Merge strategy `deep` can only be used with hashes and arrays." unless value.is_a?(Hash) || value.is_a?(Array) DeepMerge.deep_merge!(memo, value, merge_hash_arrays: true) end diff --git a/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml b/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml index 5f46d2d2..be7caf03 100644 --- a/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml +++ b/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml @@ -19,6 +19,8 @@ hdm_nested_hash: integer: 32 added_by_common: common hdm_mixed_types: 42 +hdm_mixed_types2: + from_common: 42 lookup_options: '^hdm_duplicates': merge: hash diff --git a/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml b/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml index fefa500d..00a44de1 100644 --- a/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml +++ b/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml @@ -16,3 +16,4 @@ hdm_nested_hash: integer: 5 hdm_mixed_types: from_node: 23 +hdm_mixed_types2: 23 diff --git a/test/models/hiera_data/lookup_test.rb b/test/models/hiera_data/lookup_test.rb index 03e6376d..42a4e690 100644 --- a/test/models/hiera_data/lookup_test.rb +++ b/test/models/hiera_data/lookup_test.rb @@ -118,6 +118,18 @@ class LookupTest < ActiveSupport::TestCase assert_equal expected, result end + test "looking up a mixed value key where a hash is on the highest layer with merge strategy `deep`" do + result = perform_lookup("hdm_mixed_types", merge_strategy: :deep) + + assert_equal({ "from_node" => 23 }, result) + end + + test "looking up a mixed value key where a hash is on the lowest layer with merge strategy `deep`" do + result = perform_lookup("hdm_mixed_types2", merge_strategy: :deep) + + assert_equal 23, result + end + private def perform_lookup(key, merge_strategy:)