@@ -91,6 +91,61 @@ def expect_lookup_with_output(exitcode, out)
91
91
expect_lookup_with_output ( 0 , /--- value from per node data/ )
92
92
end
93
93
94
+ it "resolves hiera data using a top-level node parameter from enc" do
95
+ Puppet . settings [ :node_terminus ] = 'exec'
96
+ enc = tmpfile ( 'enc.sh' )
97
+ Puppet . settings [ :external_nodes ] = enc
98
+ File . write ( File . join ( env_dir , env_name , 'hiera.yaml' ) , <<~YAML )
99
+ ---
100
+ version: 5
101
+ hierarchy:
102
+ - name: "Node parameters"
103
+ data_hash: yaml_data
104
+ path: "%{site}.yaml"
105
+ YAML
106
+
107
+ File . write ( File . join ( env_dir , env_name , 'data' , "pdx.yaml" ) , <<~YAML )
108
+ ---
109
+ key: value
110
+ YAML
111
+ allow ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( [ enc , fqdn ] , anything ) . and_return ( <<~YAML )
112
+ parameters:
113
+ site: pdx
114
+ YAML
115
+ app . command_line . args << 'key' << '--compile'
116
+ Puppet . initialize_settings ( [ '-E' , env_name ] )
117
+ expect_lookup_with_output ( 0 , /--- value/ )
118
+ end
119
+
120
+ it "prefers the environment specified on the commandline over the enc environment" do
121
+ Puppet . settings [ :node_terminus ] = 'exec'
122
+ enc = tmpfile ( 'enc.sh' )
123
+ Puppet . settings [ :external_nodes ] = enc
124
+ File . write ( File . join ( env_dir , env_name , 'hiera.yaml' ) , <<~YAML )
125
+ ---
126
+ version: 5
127
+ hierarchy:
128
+ - name: "Node parameters"
129
+ data_hash: yaml_data
130
+ path: "%{site}.yaml"
131
+ YAML
132
+
133
+ File . write ( File . join ( env_dir , env_name , 'data' , "pdx.yaml" ) , <<~YAML )
134
+ ---
135
+ key: value
136
+ YAML
137
+ allow ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( [ enc , fqdn ] , anything ) . and_return ( <<~YAML )
138
+ ---
139
+ # return 'someother' environment because it doesn't have any hiera data
140
+ environment: someother
141
+ parameters:
142
+ site: pdx
143
+ YAML
144
+ app . command_line . args << 'key' << '--compile'
145
+ Puppet . initialize_settings ( [ '-E' , env_name ] )
146
+ expect_lookup_with_output ( 0 , /--- value/ )
147
+ end
148
+
94
149
it 'loads trusted information from the node certificate' do
95
150
Puppet . settings [ :node_terminus ] = 'exec'
96
151
expect_any_instance_of ( Puppet ::Node ::Exec ) . to receive ( :find ) do |args |
0 commit comments