|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
| 3 | +# rubocop:disable Metrics/BlockLength |
3 | 4 | describe Puppet::Type.type(:node_group) do |
4 | 5 | it 'allows agent-specified environment' do |
5 | 6 | expect { |
|
73 | 74 | end |
74 | 75 |
|
75 | 76 | describe 'purge_behavior' do |
76 | | - |
77 | | - |
78 | 77 | let(:and_rule) do |
79 | 78 | ['and', |
80 | 79 | ['~', ['fact', 'fact1'], 'value1'], |
|
105 | 104 | } |
106 | 105 | end |
107 | 106 | let(:group_with_merged_and_rule) do |
108 | | - ["or", |
109 | | - ["and", |
110 | | - ["~", ["fact", "fact1"], "value1"], |
111 | | - ["~", ["fact", "fact2"], "value2"]], |
112 | | - ["~", ["fact", "fact1"], "value1"], |
113 | | - ["~", ["fact", "fact2"], "value2"]] |
114 | | - end |
115 | | - |
| 107 | + ['or', |
| 108 | + ['and', |
| 109 | + ['~', ['fact', 'fact1'], 'value1'], |
| 110 | + ['~', ['fact', 'fact2'], 'value2']], |
| 111 | + ['~', ['fact', 'fact1'], 'value1'], |
| 112 | + ['~', ['fact', 'fact2'], 'value2']] |
| 113 | + end |
| 114 | + |
116 | 115 | it 'replaces by default' do |
117 | 116 | rsrc = described_class.new(group_with_rule) |
118 | 117 | # this is simulated data from the classifier service |
|
163 | 162 | # to the end |
164 | 163 | # also the merging optimizes the pinned nodes to remove redundants. |
165 | 164 | let(:merged_pinned_nodes_and_rule) do |
166 | | - ["or", |
167 | | - ["and", |
168 | | - ["~", ["fact", "fact1"], "value1"], |
169 | | - ["~", ["fact", "fact2"], "value2"]], |
170 | | - ["=", "name", "value1"], |
171 | | - ["=", "name", "value2"]] |
| 165 | + ['or', |
| 166 | + ['and', |
| 167 | + ['~', ['fact', 'fact1'], 'value1'], |
| 168 | + ['~', ['fact', 'fact2'], 'value2']], |
| 169 | + ['=', 'name', 'value1'], |
| 170 | + ['=', 'name', 'value2']] |
172 | 171 | end |
173 | 172 |
|
174 | 173 | let(:merged_pinned_nodes_or_rule) do |
175 | | - ["or", |
176 | | - ["~", ["fact", "fact1"], "value1"], |
177 | | - ["~", ["fact", "fact2"], "value2"], |
178 | | - ["=", "name", "value1"], |
179 | | - ["=", "name", "value2"]] |
| 174 | + ['or', |
| 175 | + ['~', ['fact', 'fact1'], 'value1'], |
| 176 | + ['~', ['fact', 'fact2'], 'value2'], |
| 177 | + ['=', 'name', 'value1'], |
| 178 | + ['=', 'name', 'value2']] |
180 | 179 | end |
181 | 180 |
|
182 | 181 | it 'matches rule exactly by default' do |
|
199 | 198 |
|
200 | 199 | it 'merges pinned node correctly when purge behaviour set to :none' do |
201 | 200 | rsrc = described_class.new(group_with_pinned_nodes.merge(purge_behavior: 'none')) |
202 | | - allow(rsrc.property(:rule)).to receive(:retrieve).and_return(["=", "name", "value2"]) |
| 201 | + allow(rsrc.property(:rule)).to receive(:retrieve).and_return(['=', 'name', 'value2']) |
203 | 202 | # redundant node pinning is removed |
204 | | - expect(rsrc.property(:rule).should).to eq ["or", ["=", "name", "value2"], ["=", "name", "value1"]] |
| 203 | + expect(rsrc.property(:rule).should).to eq ['or', ['=', 'name', 'value2'], ['=', 'name', 'value1']] |
205 | 204 | end |
206 | 205 |
|
207 | 206 | it 'replaces rule when purge behaviour set to :all' do |
|
215 | 214 | allow(rsrc.property(:rule)).to receive(:retrieve).and_return(and_rule) |
216 | 215 | expect(rsrc.property(:rule).should).to eq group_with_pinned_nodes[:rule] |
217 | 216 | end |
218 | | - |
219 | 217 | end |
220 | 218 |
|
221 | 219 | describe 'group with top-level and clause' do |
|
236 | 234 | end |
237 | 235 |
|
238 | 236 | let(:rule_combined_and_clauses) do |
239 | | - ["and", |
240 | | - ["~", ["fact", "fact1"], "value1"], |
241 | | - ["~", ["fact", "fact2"], "value2"], |
242 | | - ["~", ["fact", "pe_server_version"], ".+"]] |
| 237 | + ['and', |
| 238 | + ['~', ['fact', 'fact1'], 'value1'], |
| 239 | + ['~', ['fact', 'fact2'], 'value2'], |
| 240 | + ['~', ['fact', 'pe_server_version'], '.+']] |
243 | 241 | end |
244 | 242 |
|
245 | 243 | let(:rule_combined_or_clauses) do |
246 | | - ["or", |
247 | | - ["~", ["fact", "fact1"], "value1"], |
248 | | - ["~", ["fact", "fact2"], "value2"], |
249 | | - ["and", ["~", ["fact", "pe_server_version"], ".+"]]] |
| 244 | + ['or', |
| 245 | + ['~', ['fact', 'fact1'], 'value1'], |
| 246 | + ['~', ['fact', 'fact2'], 'value2'], |
| 247 | + ['and', ['~', ['fact', 'pe_server_version'], '.+']]] |
250 | 248 | end |
251 | 249 |
|
252 | 250 | it 'replaces rule exactly by default' do |
|
269 | 267 |
|
270 | 268 | it 'merges pinned node correctly when purge behaviour set to :none' do |
271 | 269 | rsrc = described_class.new(group_with_and_clause.merge(purge_behavior: 'none')) |
272 | | - allow(rsrc.property(:rule)).to receive(:retrieve).and_return(["=", "name", "value2"]) |
| 270 | + allow(rsrc.property(:rule)).to receive(:retrieve).and_return(['=', 'name', 'value2']) |
273 | 271 | # redundant node pinning is removed |
274 | | - expect(rsrc.property(:rule).should).to eq ["or", ["=", "name", "value2"], ["and", ["~", ["fact", "pe_server_version"], ".+"]]] |
| 272 | + expect(rsrc.property(:rule).should).to eq ['or', ['=', 'name', 'value2'], ['and', ['~', ['fact', 'pe_server_version'], '.+']]] |
275 | 273 | end |
276 | 274 |
|
277 | 275 | it 'replaces rule when purge behaviour set to :all' do |
|
285 | 283 | allow(rsrc.property(:rule)).to receive(:retrieve).and_return(and_rule) |
286 | 284 | expect(rsrc.property(:rule).should).to eq group_with_and_clause[:rule] |
287 | 285 | end |
288 | | - |
289 | 286 | end |
290 | 287 |
|
291 | 288 | describe 'resource hash' do |
|
305 | 302 | }, |
306 | 303 | } |
307 | 304 | end |
308 | | - |
| 305 | + |
309 | 306 | let(:existing_data) do |
310 | 307 | { 'data::class1' => { 'param1' => 'existing', |
311 | 308 | 'param3' => 'existing' }, |
|
321 | 318 | 'data::class3' => { 'param1' => 'existing', |
322 | 319 | 'param2' => 'existing' } } |
323 | 320 | end |
324 | | - |
| 321 | + |
325 | 322 | let(:existing_classes) do |
326 | 323 | { 'classes::class1' => { 'param1' => 'existing', |
327 | 324 | 'param3' => 'existing' }, |
|
335 | 332 | 'classes::class3' => { 'param1' => 'existing', |
336 | 333 | 'param2' => 'existing' } } |
337 | 334 | end |
338 | | - |
| 335 | + |
339 | 336 | it 'matches classes and data exactly by default' do |
340 | 337 | rsrc = described_class.new(resource_hash) |
341 | 338 | allow(rsrc.property(:data)).to receive(:retrieve).and_return(existing_data) |
|
368 | 365 | expect(rsrc.property(:classes).should).to eq(resource_hash[:classes]) |
369 | 366 | end |
370 | 367 | end |
371 | | - |
372 | 368 | end |
373 | 369 |
|
374 | 370 | describe '.insync? for data, classes' do |
|
414 | 410 | end |
415 | 411 | end |
416 | 412 | end |
| 413 | +# rubocop:enable Metrics/BlockLength |
0 commit comments