3
3
require 'puppet_spec/files'
4
4
require 'puppet/pops'
5
5
require 'deep_merge/core'
6
- require 'hiera'
7
6
8
7
describe "The lookup function" do
9
8
include PuppetSpec ::Compiler
@@ -1652,7 +1651,7 @@ def uri_test_func(options, context)
1652
1651
end
1653
1652
end
1654
1653
1655
- context 'version 3' do
1654
+ context 'version 3' , :if => Puppet . features . hiera? do
1656
1655
it 'finds data in in global layer and reports deprecation warnings for hiera.yaml' do
1657
1656
expect ( lookup ( 'a' ) ) . to eql ( 'value a (from global)' )
1658
1657
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)
1697
1696
expect ( lookup ( 'datasources' ) ) . to eql ( [ 'common' , 'example.com' ] )
1698
1697
end
1699
1698
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
+
1700
1707
it 'delegates configured hocon backend to hocon_data function' do
1701
1708
expect ( explain ( 'xs' ) ) . to match ( /Hierarchy entry "hocon"\n .*\n .*\n .*"common"\n \s *Found key: "xs"/m )
1702
1709
end
@@ -1705,6 +1712,18 @@ def uri_test_func(options, context)
1705
1712
expect ( lookup ( 'xs.subkey' ) ) . to eql ( 'value xs.subkey (from global hocon)' )
1706
1713
end
1707
1714
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
+
1708
1727
context 'with a module data provider' do
1709
1728
let ( :module_files ) do
1710
1729
{
@@ -2041,18 +2060,6 @@ def uri_test_func(options, context)
2041
2060
paths:
2042
2061
- common.conf
2043
2062
- "%{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"
2056
2063
YAML
2057
2064
end
2058
2065
@@ -2067,7 +2074,6 @@ def uri_test_func(options, context)
2067
2074
expect ( explanation ) . to include ( 'Hierarchy entry "Yaml"' )
2068
2075
expect ( explanation ) . to include ( 'Hierarchy entry "Json"' )
2069
2076
expect ( explanation ) . to include ( 'Hierarchy entry "Hocon"' )
2070
- expect ( explanation ) . to include ( 'Hierarchy entry "Custom"' )
2071
2077
expect ( explanation ) . to include ( 'Found key: "a" value: "value a (from global)"' )
2072
2078
end
2073
2079
@@ -2079,35 +2085,10 @@ def uri_test_func(options, context)
2079
2085
'caa' => 'value hash_c.hash_ca.caa (from environment)' ,
2080
2086
'cab' => 'value hash_c.hash_ca.cab (from global)' ,
2081
2087
'cac' => 'value hash_c.hash_ca.cac (from global json)' ,
2082
- 'cad' => 'value hash_c.hash_ca.cad (from global custom)'
2083
2088
}
2084
2089
} )
2085
2090
end
2086
2091
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
-
2111
2092
it 'provides a sensible error message when the hocon library is not loaded' do
2112
2093
allow ( Puppet . features ) . to receive ( :hocon? ) . and_return ( false )
2113
2094
@@ -2156,7 +2137,7 @@ def uri_test_func(options, context)
2156
2137
end
2157
2138
end
2158
2139
2159
- context 'and eyaml_lookup_key function' do
2140
+ context 'and eyaml_lookup_key function' , :if => Puppet . features . hiera_eyaml? do
2160
2141
let ( :hiera_yaml ) { <<-YAML . unindent }
2161
2142
version: 5
2162
2143
hierarchy:
@@ -2171,7 +2152,7 @@ def uri_test_func(options, context)
2171
2152
end
2172
2153
end
2173
2154
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
2175
2156
let ( :hiera_yaml ) do
2176
2157
<<-YAML . unindent
2177
2158
---
@@ -2215,7 +2196,7 @@ def uri_test_func(options, context)
2215
2196
expect { lookup ( 'mod_a::b' ) } . to raise_error ( Puppet ::DataBinding ::LookupError , /did not find a value for the name 'mod_a::b'/ )
2216
2197
end
2217
2198
2218
- context 'with a Hiera v3 configuration' do
2199
+ context 'with a Hiera v3 configuration' , :if => Puppet . features . hiera? do
2219
2200
let ( :mod_a_files ) do
2220
2201
{
2221
2202
'mod_a' => {
@@ -2992,7 +2973,7 @@ def ruby_dig(segments, options, context)
2992
2973
end
2993
2974
end
2994
2975
2995
- context 'and an eyaml lookup_key function' do
2976
+ context 'and an eyaml lookup_key function' , :if => Puppet . features . hiera_eyaml? do
2996
2977
let ( :private_key_name ) { 'private_key.pkcs7.pem' }
2997
2978
let ( :public_key_name ) { 'public_key.pkcs7.pem' }
2998
2979
@@ -3294,7 +3275,7 @@ def ruby_dig(segments, options, context)
3294
3275
expect ( lookup ( 'array_a' ) ) . to eql ( [ 'array_a[0]' , 'array_a[1]' ] )
3295
3276
end
3296
3277
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
3298
3279
let ( :environment_files ) { { } }
3299
3280
let ( :data_file_content ) { <<-YAML . unindent }
3300
3281
a: >
0 commit comments