33require 'puppet_spec/files'
44require 'puppet/pops'
55require 'deep_merge/core'
6- require 'hiera'
76
87describe "The lookup function" do
98 include PuppetSpec ::Compiler
@@ -1652,7 +1651,7 @@ def uri_test_func(options, context)
16521651 end
16531652 end
16541653
1655- context 'version 3' do
1654+ context 'version 3' , :if => Puppet . features . hiera? do
16561655 it 'finds data in in global layer and reports deprecation warnings for hiera.yaml' do
16571656 expect ( lookup ( 'a' ) ) . to eql ( 'value a (from global)' )
16581657 expect ( warnings ) . to include ( /Use of 'hiera.yaml' version 3 is deprecated. It should be converted to version 5/ )
@@ -1697,6 +1696,14 @@ def uri_test_func(options, context)
16971696 expect ( lookup ( 'datasources' ) ) . to eql ( [ 'common' , 'example.com' ] )
16981697 end
16991698
1699+ it 'backend specific options are propagated to custom backend' do
1700+ expect ( lookup ( 'other_option' ) ) . to eql ( 'value of other_option' )
1701+ end
1702+
1703+ it 'dotted keys are passed down to custom backend' do
1704+ expect ( lookup ( 'dotted.key' ) ) . to eql ( 'custom backend received request for dotted.key value' )
1705+ end
1706+
17001707 it 'delegates configured hocon backend to hocon_data function' do
17011708 expect ( explain ( 'xs' ) ) . to match ( /Hierarchy entry "hocon"\n .*\n .*\n .*"common"\n \s *Found key: "xs"/m )
17021709 end
@@ -1705,6 +1712,18 @@ def uri_test_func(options, context)
17051712 expect ( lookup ( 'xs.subkey' ) ) . to eql ( 'value xs.subkey (from global hocon)' )
17061713 end
17071714
1715+ it 'multiple hiera3_backend declarations can be used and are merged into the generated config' do
1716+ expect ( lookup ( [ 'datasources' , 'other_option' ] ) ) . to eql ( [ [ 'common' , 'example.com' ] , 'value of other_option' ] )
1717+ expect ( Hiera ::Config . instance_variable_get ( :@config ) ) . to eql (
1718+ {
1719+ :backends => [ 'custom' , 'other' ] ,
1720+ :hierarchy => [ 'common' , '%{domain}' ] ,
1721+ :custom => { :datadir => "#{ code_dir } /hieradata" } ,
1722+ :other => { :other_option => 'value of other_option' , :datadir => "#{ code_dir } /hieradata" } ,
1723+ :logger => 'puppet'
1724+ } )
1725+ end
1726+
17081727 context 'with a module data provider' do
17091728 let ( :module_files ) do
17101729 {
@@ -2041,18 +2060,6 @@ def uri_test_func(options, context)
20412060 paths:
20422061 - common.conf
20432062 - "%{domain}.conf"
2044- - name: Custom
2045- hiera3_backend: custom
2046- paths:
2047- - common.custom
2048- - "%{domain}.custom"
2049- - name: Other
2050- hiera3_backend: other
2051- options:
2052- other_option: value of other_option
2053- paths:
2054- - common.other
2055- - "%{domain}.other"
20562063 YAML
20572064 end
20582065
@@ -2067,7 +2074,6 @@ def uri_test_func(options, context)
20672074 expect ( explanation ) . to include ( 'Hierarchy entry "Yaml"' )
20682075 expect ( explanation ) . to include ( 'Hierarchy entry "Json"' )
20692076 expect ( explanation ) . to include ( 'Hierarchy entry "Hocon"' )
2070- expect ( explanation ) . to include ( 'Hierarchy entry "Custom"' )
20712077 expect ( explanation ) . to include ( 'Found key: "a" value: "value a (from global)"' )
20722078 end
20732079
@@ -2079,35 +2085,10 @@ def uri_test_func(options, context)
20792085 'caa' => 'value hash_c.hash_ca.caa (from environment)' ,
20802086 'cab' => 'value hash_c.hash_ca.cab (from global)' ,
20812087 'cac' => 'value hash_c.hash_ca.cac (from global json)' ,
2082- 'cad' => 'value hash_c.hash_ca.cad (from global custom)'
20832088 }
20842089 } )
20852090 end
20862091
2087- it 'backend data sources are propagated to custom backend' do
2088- expect ( lookup ( 'datasources' ) ) . to eql ( [ 'common' , 'example.com' ] )
2089- end
2090-
2091- it 'backend specific options are propagated to custom backend' do
2092- expect ( lookup ( 'other_option' ) ) . to eql ( 'value of other_option' )
2093- end
2094-
2095- it 'dotted keys are passed down to custom backend' do
2096- expect ( lookup ( 'dotted.key' ) ) . to eql ( 'custom backend received request for dotted.key value' )
2097- end
2098-
2099- it 'multiple hiera3_backend declarations can be used and are merged into the generated config' do
2100- expect ( lookup ( [ 'datasources' , 'other_option' ] ) ) . to eql ( [ [ 'common' , 'example.com' ] , 'value of other_option' ] )
2101- expect ( Hiera ::Config . instance_variable_get ( :@config ) ) . to eql (
2102- {
2103- :backends => [ 'custom' , 'other' ] ,
2104- :hierarchy => [ 'common' , '%{domain}' ] ,
2105- :custom => { :datadir => "#{ code_dir } /hieradata" } ,
2106- :other => { :other_option => 'value of other_option' , :datadir => "#{ code_dir } /hieradata" } ,
2107- :logger => 'puppet'
2108- } )
2109- end
2110-
21112092 it 'provides a sensible error message when the hocon library is not loaded' do
21122093 allow ( Puppet . features ) . to receive ( :hocon? ) . and_return ( false )
21132094
@@ -2156,7 +2137,7 @@ def uri_test_func(options, context)
21562137 end
21572138 end
21582139
2159- context 'and eyaml_lookup_key function' do
2140+ context 'and eyaml_lookup_key function' , :if => Puppet . features . hiera_eyaml? do
21602141 let ( :hiera_yaml ) { <<-YAML . unindent }
21612142 version: 5
21622143 hierarchy:
@@ -2171,7 +2152,7 @@ def uri_test_func(options, context)
21712152 end
21722153 end
21732154
2174- context 'with a hiera3_backend that has no paths' do
2155+ context 'with a hiera3_backend that has no paths' , :if => Puppet . features . hiera? do
21752156 let ( :hiera_yaml ) do
21762157 <<-YAML . unindent
21772158 ---
@@ -2215,7 +2196,7 @@ def uri_test_func(options, context)
22152196 expect { lookup ( 'mod_a::b' ) } . to raise_error ( Puppet ::DataBinding ::LookupError , /did not find a value for the name 'mod_a::b'/ )
22162197 end
22172198
2218- context 'with a Hiera v3 configuration' do
2199+ context 'with a Hiera v3 configuration' , :if => Puppet . features . hiera? do
22192200 let ( :mod_a_files ) do
22202201 {
22212202 'mod_a' => {
@@ -2992,7 +2973,7 @@ def ruby_dig(segments, options, context)
29922973 end
29932974 end
29942975
2995- context 'and an eyaml lookup_key function' do
2976+ context 'and an eyaml lookup_key function' , :if => Puppet . features . hiera_eyaml? do
29962977 let ( :private_key_name ) { 'private_key.pkcs7.pem' }
29972978 let ( :public_key_name ) { 'public_key.pkcs7.pem' }
29982979
@@ -3294,7 +3275,7 @@ def ruby_dig(segments, options, context)
32943275 expect ( lookup ( 'array_a' ) ) . to eql ( [ 'array_a[0]' , 'array_a[1]' ] )
32953276 end
32963277
3297- context 'declared in global scope as a Hiera v3 backend' do
3278+ context 'declared in global scope as a Hiera v3 backend' , :if => Puppet . features . hiera? do
32983279 let ( :environment_files ) { { } }
32993280 let ( :data_file_content ) { <<-YAML . unindent }
33003281 a: >
0 commit comments