clc-cheffish 0.8.clc → 0.8.3.clc

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require 'chef/provider/chef_node'
5
5
  describe Chef::Resource::ChefNode do
6
6
  extend SpecSupport
7
7
 
8
- when_the_chef_server 'is in multi-org mode', :osc_compat => false, :single_org => false do
8
+ when_the_chef_12_server 'is in multi-org mode' do
9
9
  organization 'foo'
10
10
 
11
11
  before :each do
@@ -109,88 +109,690 @@ describe Chef::Resource::ChefNode do
109
109
  end
110
110
  end
111
111
 
112
- context 'has a node named "blah" with everything in it' do
113
- node 'blah', {
114
- 'chef_environment' => 'blah',
115
- 'run_list' => [ 'recipe[bjork]' ],
116
- 'normal' => { 'foo' => 'bar', 'tags' => [ 'a', 'b' ] },
117
- 'default' => { 'foo2' => 'bar2' },
118
- 'automatic' => { 'foo3' => 'bar3' },
119
- 'override' => { 'foo4' => 'bar4' }
120
- }
112
+ describe '#complete' do
113
+ context 'when the Chef server has a node named "blah" with everything in it' do
114
+ node 'blah', {
115
+ 'chef_environment' => 'blah',
116
+ 'run_list' => [ 'recipe[bjork]' ],
117
+ 'normal' => { 'foo' => 'bar', 'tags' => [ 'a', 'b' ] },
118
+ 'default' => { 'foo2' => 'bar2' },
119
+ 'automatic' => { 'foo3' => 'bar3' },
120
+ 'override' => { 'foo4' => 'bar4' }
121
+ }
122
+
123
+ it 'chef_node with no attributes modifies nothing' do
124
+ run_recipe do
125
+ chef_node 'blah'
126
+ end
127
+ expect(get('nodes/blah')).to include(
128
+ 'name' => 'blah',
129
+ 'chef_environment' => 'blah',
130
+ 'run_list' => [ 'recipe[bjork]' ],
131
+ 'normal' => { 'foo' => 'bar', 'tags' => [ 'a', 'b' ] },
132
+ 'default' => { 'foo2' => 'bar2' },
133
+ 'automatic' => { 'foo3' => 'bar3' },
134
+ 'override' => { 'foo4' => 'bar4' }
135
+ )
136
+ end
121
137
 
122
- context 'with chef_node "blah"' do
123
- with_converge do
124
- chef_node 'blah'
138
+ it 'chef_node with complete true removes everything except default, automatic and override' do
139
+ run_recipe do
140
+ chef_node 'blah' do
141
+ complete true
142
+ end
143
+ end
144
+ expect(get('nodes/blah')).to include(
145
+ 'name' => 'blah',
146
+ 'chef_environment' => '_default',
147
+ 'run_list' => [ ],
148
+ 'normal' => { 'tags' => [ 'a', 'b' ] },
149
+ 'default' => { 'foo2' => 'bar2' },
150
+ 'automatic' => { 'foo3' => 'bar3' },
151
+ 'override' => { 'foo4' => 'bar4' }
152
+ )
125
153
  end
126
154
 
127
- it 'nothing gets updated' do
128
- expect(chef_run).not_to have_updated 'chef_node[blah]', :create
155
+ it 'chef_node with complete true sets the given attributes' do
156
+ run_recipe do
157
+ chef_node 'blah' do
158
+ chef_environment 'x'
159
+ run_list [ 'recipe[y]' ]
160
+ attributes 'a' => 'b'
161
+ tags 'c', 'd'
162
+ complete true
163
+ end
164
+ end
165
+ expect(get('nodes/blah')).to include(
166
+ 'name' => 'blah',
167
+ 'chef_environment' => 'x',
168
+ 'run_list' => [ 'recipe[y]' ],
169
+ 'normal' => { 'a' => 'b', 'tags' => [ 'c', 'd' ] },
170
+ 'default' => { 'foo2' => 'bar2' },
171
+ 'automatic' => { 'foo3' => 'bar3' },
172
+ 'override' => { 'foo4' => 'bar4' }
173
+ )
174
+ end
175
+
176
+ it 'chef_node with complete true and partial attributes sets the given attributes' do
177
+ run_recipe do
178
+ chef_node 'blah' do
179
+ chef_environment 'x'
180
+ recipe 'y'
181
+ attribute 'a', 'b'
182
+ tags 'c', 'd'
183
+ complete true
184
+ end
185
+ end
186
+ expect(get('nodes/blah')).to include(
187
+ 'name' => 'blah',
188
+ 'chef_environment' => 'x',
189
+ 'run_list' => [ 'recipe[y]' ],
190
+ 'normal' => { 'a' => 'b', 'tags' => [ 'c', 'd' ] },
191
+ 'default' => { 'foo2' => 'bar2' },
192
+ 'automatic' => { 'foo3' => 'bar3' },
193
+ 'override' => { 'foo4' => 'bar4' }
194
+ )
129
195
  end
130
196
  end
197
+ end
131
198
 
132
- context 'with chef_node "blah" and an updated normal attribute value' do
133
- with_converge do
134
- chef_node 'blah' do
135
- attributes 'foo' => 'fum'
199
+ describe '#attributes' do
200
+ context 'with a node with normal attributes a => b and c => { d => e }' do
201
+ node 'blah', {
202
+ 'normal' => {
203
+ 'a' => 'b',
204
+ 'c' => { 'd' => 'e' },
205
+ 'tags' => [ 'a', 'b' ]
206
+ },
207
+ 'automatic' => {
208
+ 'x' => 'y'
209
+ },
210
+ 'chef_environment' => 'desert'
211
+ }
212
+
213
+ it 'chef_node with attributes {} removes all normal attributes but leaves tags, automatic and environment alone' do
214
+ run_recipe do
215
+ chef_node 'blah' do
216
+ attributes({})
217
+ end
136
218
  end
219
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
220
+ expect(get('nodes/blah')).to include(
221
+ 'normal' => { 'tags' => [ 'a', 'b' ] },
222
+ 'automatic' => { 'x' => 'y' },
223
+ 'chef_environment' => 'desert'
224
+ )
137
225
  end
138
226
 
139
- it 'new normal attribute is added' do
140
- expect(chef_run).to have_updated 'chef_node[blah]', :create
141
- node = get('nodes/blah')
142
- expect(node['normal']).to eq({ 'foo' => 'fum', 'tags' => [ 'a', 'b' ] })
227
+ it 'chef_node with attributes { c => d } replaces normal but not tags/automatic/environment' do
228
+ run_recipe do
229
+ chef_node 'blah' do
230
+ attributes 'c' => 'd'
231
+ end
232
+ end
233
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
234
+ expect(get('nodes/blah')).to include(
235
+ 'normal' => { 'c' => 'd', 'tags' => [ 'a', 'b' ] },
236
+ 'automatic' => { 'x' => 'y' },
237
+ 'chef_environment' => 'desert'
238
+ )
143
239
  end
144
- end
145
240
 
146
- context 'with chef_node "blah" and a new normal attribute' do
147
- with_converge do
148
- chef_node 'blah' do
149
- attributes 'foe' => 'fum'
241
+ it 'chef_node with attributes { c => f => g, y => z } replaces normal but not tags/automatic/environment' do
242
+ run_recipe do
243
+ chef_node 'blah' do
244
+ attributes 'c' => { 'f' => 'g' }, 'y' => 'z'
245
+ end
150
246
  end
247
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
248
+ expect(get('nodes/blah')).to include(
249
+ 'normal' => { 'c' => { 'f' => 'g' }, 'y' => 'z', 'tags' => [ 'a', 'b' ] },
250
+ 'automatic' => { 'x' => 'y' },
251
+ 'chef_environment' => 'desert'
252
+ )
151
253
  end
152
254
 
153
- it 'new normal attribute is added' do
154
- expect(chef_run).to have_updated 'chef_node[blah]', :create
155
- node = get('nodes/blah')
156
- expect(node['normal']).to eq({ 'foe' => 'fum', 'foo' => 'bar', 'tags' => [ 'a', 'b' ] })
255
+ it 'chef_node with attributes { tags => [ "x" ] } replaces normal and tags but not automatic/environment' do
256
+ run_recipe do
257
+ chef_node 'blah' do
258
+ attributes 'tags' => [ 'x' ]
259
+ end
260
+ end
261
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
262
+ expect(get('nodes/blah')).to include(
263
+ 'normal' => { 'tags' => [ 'x' ] },
264
+ 'automatic' => { 'x' => 'y' },
265
+ 'chef_environment' => 'desert'
266
+ )
267
+ end
268
+
269
+ it 'chef_node with tags "x" and attributes { "tags" => [ "y" ] } sets tags to "x"' do
270
+ run_recipe do
271
+ chef_node 'blah' do
272
+ tags 'x'
273
+ attributes 'tags' => [ 'y' ]
274
+ end
275
+ end
276
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
277
+ expect(get('nodes/blah')).to include(
278
+ 'normal' => {
279
+ 'tags' => [ 'x' ]
280
+ },
281
+ 'automatic' => { 'x' => 'y' },
282
+ 'chef_environment' => 'desert'
283
+ )
157
284
  end
158
285
  end
286
+ end
159
287
 
160
- context 'with chef_node "blah" with complete true' do
161
- with_converge do
162
- chef_node 'blah' do
163
- complete true
288
+ describe '#attribute' do
289
+ context 'with a node with normal attributes a => b and c => { d => e }' do
290
+ node 'blah', {
291
+ 'normal' => {
292
+ 'a' => 'b',
293
+ 'c' => { 'd' => 'e' },
294
+ 'tags' => [ 'a', 'b' ]
295
+ },
296
+ 'automatic' => {
297
+ 'x' => 'y'
298
+ },
299
+ 'chef_environment' => 'desert'
300
+ }
301
+
302
+ context 'basic scenarios' do
303
+ it 'chef_node with no attributes, leaves it alone' do
304
+ run_recipe do
305
+ chef_node 'blah'
306
+ end
307
+ expect(chef_run).not_to have_updated('chef_node[blah]', :create)
308
+ expect(get('nodes/blah')).to include(
309
+ 'normal' => {
310
+ 'a' => 'b',
311
+ 'c' => { 'd' => 'e' },
312
+ 'tags' => [ 'a', 'b' ]
313
+ },
314
+ 'automatic' => { 'x' => 'y' },
315
+ 'chef_environment' => 'desert'
316
+ )
317
+ end
318
+
319
+ it 'chef_node with attribute d, e adds the attribute' do
320
+ run_recipe do
321
+ chef_node 'blah' do
322
+ attribute 'd', 'e'
323
+ end
324
+ end
325
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
326
+ expect(get('nodes/blah')).to include(
327
+ 'normal' => {
328
+ 'a' => 'b',
329
+ 'c' => { 'd' => 'e' },
330
+ 'd' => 'e',
331
+ 'tags' => [ 'a', 'b' ]
332
+ },
333
+ 'automatic' => { 'x' => 'y' },
334
+ 'chef_environment' => 'desert'
335
+ )
336
+ end
337
+
338
+ it 'chef_node with attribute tags, [ "x" ] replaces tags' do
339
+ run_recipe do
340
+ chef_node 'blah' do
341
+ attribute 'tags', [ 'x' ]
342
+ end
343
+ end
344
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
345
+ expect(get('nodes/blah')).to include(
346
+ 'normal' => {
347
+ 'a' => 'b',
348
+ 'c' => { 'd' => 'e' },
349
+ 'tags' => [ 'x' ]
350
+ },
351
+ 'automatic' => { 'x' => 'y' },
352
+ 'chef_environment' => 'desert'
353
+ )
354
+ end
355
+
356
+ it 'chef_node with attribute c, x replaces the attribute' do
357
+ run_recipe do
358
+ chef_node 'blah' do
359
+ attribute 'c', 'x'
360
+ end
361
+ end
362
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
363
+ expect(get('nodes/blah')).to include(
364
+ 'normal' => {
365
+ 'a' => 'b',
366
+ 'c' => 'x',
367
+ 'tags' => [ 'a', 'b' ]
368
+ },
369
+ 'automatic' => { 'x' => 'y' },
370
+ 'chef_environment' => 'desert'
371
+ )
372
+ end
373
+
374
+ it 'chef_node with attribute c, { d => x } replaces the attribute' do
375
+ run_recipe do
376
+ chef_node 'blah' do
377
+ attribute 'c', { 'd' => 'x' }
378
+ end
379
+ end
380
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
381
+ expect(get('nodes/blah')).to include(
382
+ 'normal' => {
383
+ 'a' => 'b',
384
+ 'c' => { 'd' => 'x' },
385
+ 'tags' => [ 'a', 'b' ]
386
+ },
387
+ 'automatic' => { 'x' => 'y' },
388
+ 'chef_environment' => 'desert'
389
+ )
390
+ end
391
+
392
+ it 'chef_node with attribute [ c, d ], x replaces the attribute' do
393
+ run_recipe do
394
+ chef_node 'blah' do
395
+ attribute [ 'c', 'd' ], 'x'
396
+ end
397
+ end
398
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
399
+ expect(get('nodes/blah')).to include(
400
+ 'normal' => {
401
+ 'a' => 'b',
402
+ 'c' => { 'd' => 'x' },
403
+ 'tags' => [ 'a', 'b' ]
404
+ },
405
+ 'automatic' => { 'x' => 'y' },
406
+ 'chef_environment' => 'desert'
407
+ )
408
+ end
409
+
410
+ it 'chef_node with attribute [ a, b ], x raises an error' do
411
+ expect do
412
+ run_recipe do
413
+ chef_node 'blah' do
414
+ attribute [ 'a', 'b' ], 'x'
415
+ end
416
+ end
417
+ end.to raise_error /Attempt to set \["a", "b"\] to x when \["a"\] is not a hash/
418
+ end
419
+
420
+ it 'chef_node with attribute [ a, b, c ], x raises an error' do
421
+ expect do
422
+ run_recipe do
423
+ chef_node 'blah' do
424
+ attribute [ 'a', 'b', 'c' ], 'x'
425
+ end
426
+ end
427
+ end.to raise_error /Attempt to set \["a", "b", "c"\] to x when \["a"\] is not a hash/
428
+ end
429
+
430
+ it 'chef_node with attribute [ x, y ], z adds a new attribute' do
431
+ run_recipe do
432
+ chef_node 'blah' do
433
+ attribute [ 'x', 'y' ], 'z'
434
+ end
435
+ end
436
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
437
+ expect(get('nodes/blah')).to include(
438
+ 'normal' => {
439
+ 'a' => 'b',
440
+ 'c' => { 'd' => 'e' },
441
+ 'x' => { 'y' => 'z' },
442
+ 'tags' => [ 'a', 'b' ]
443
+ },
444
+ 'automatic' => { 'x' => 'y' },
445
+ 'chef_environment' => 'desert'
446
+ )
447
+ end
448
+
449
+ it 'chef_node with attribute [], {} clears all attributes' do
450
+ run_recipe do
451
+ chef_node 'blah' do
452
+ attribute([], {})
453
+ end
454
+ end
455
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
456
+ expect(get('nodes/blah')).to include(
457
+ 'normal' => { },
458
+ 'automatic' => { 'x' => 'y' },
459
+ 'chef_environment' => 'desert'
460
+ )
164
461
  end
165
462
  end
166
463
 
167
- it 'default, automatic and override attributes are left alone' do
168
- expect(chef_run).to have_updated 'chef_node[blah]', :create
169
- node = get('nodes/blah')
170
- expect(node['chef_environment']).to eq('_default')
171
- expect(node['run_list']).to eq([])
172
- expect(node['normal']).to eq({ 'tags' => [ 'a', 'b' ] })
173
- expect(node['default']).to eq({ 'foo2' => 'bar2' })
174
- expect(node['automatic']).to eq({ 'foo3' => 'bar3' })
175
- expect(node['override']).to eq({ 'foo4' => 'bar4' })
464
+ context 'delete' do
465
+ it 'chef_node with attribute a, :delete deletes the attribute' do
466
+ run_recipe do
467
+ chef_node 'blah' do
468
+ attribute 'a', :delete
469
+ end
470
+ end
471
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
472
+ expect(get('nodes/blah')).to include(
473
+ 'normal' => {
474
+ 'c' => { 'd' => 'e' },
475
+ 'tags' => [ 'a', 'b' ]
476
+ },
477
+ 'automatic' => { 'x' => 'y' },
478
+ 'chef_environment' => 'desert'
479
+ )
480
+ end
481
+
482
+ it 'chef_node with attribute c, :delete deletes the attribute' do
483
+ run_recipe do
484
+ chef_node 'blah' do
485
+ attribute 'c', :delete
486
+ end
487
+ end
488
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
489
+ expect(get('nodes/blah')).to include(
490
+ 'normal' => {
491
+ 'a' => 'b',
492
+ 'tags' => [ 'a', 'b' ]
493
+ },
494
+ 'automatic' => { 'x' => 'y' },
495
+ 'chef_environment' => 'desert'
496
+ )
497
+ end
498
+
499
+ it 'chef_node with attribute [ c, d ], :delete deletes the attribute' do
500
+ run_recipe do
501
+ chef_node 'blah' do
502
+ attribute [ 'c', 'd' ], :delete
503
+ end
504
+ end
505
+ expect(chef_run).to have_updated('chef_node[blah]', :create)
506
+ expect(get('nodes/blah')).to include(
507
+ 'normal' => {
508
+ 'a' => 'b',
509
+ 'c' => {},
510
+ 'tags' => [ 'a', 'b' ]
511
+ },
512
+ 'automatic' => { 'x' => 'y' },
513
+ 'chef_environment' => 'desert'
514
+ )
515
+ end
516
+
517
+ it 'chef_node with attribute xyz, :delete does nothing' do
518
+ run_recipe do
519
+ chef_node 'blah' do
520
+ attribute 'xyz', :delete
521
+ end
522
+ end
523
+ expect(chef_run).not_to have_updated('chef_node[blah]', :create)
524
+ expect(get('nodes/blah')).to include(
525
+ 'normal' => {
526
+ 'a' => 'b',
527
+ 'c' => { 'd' => 'e' },
528
+ 'tags' => [ 'a', 'b' ]
529
+ },
530
+ 'automatic' => { 'x' => 'y' },
531
+ 'chef_environment' => 'desert'
532
+ )
533
+ end
534
+
535
+ it 'chef_node with attribute [ c, x ], :delete does nothing' do
536
+ run_recipe do
537
+ chef_node 'blah' do
538
+ attribute [ 'c', 'x' ], :delete
539
+ end
540
+ end
541
+ expect(chef_run).not_to have_updated('chef_node[blah]', :create)
542
+ expect(get('nodes/blah')).to include(
543
+ 'normal' => {
544
+ 'a' => 'b',
545
+ 'c' => { 'd' => 'e' },
546
+ 'tags' => [ 'a', 'b' ]
547
+ },
548
+ 'automatic' => { 'x' => 'y' },
549
+ 'chef_environment' => 'desert'
550
+ )
551
+ end
176
552
  end
177
- end
178
553
 
179
- context 'with chef_node "blah", complete true and a new normal attribute' do
180
- with_converge do
181
- chef_node 'blah' do
182
- attributes 'foe' => 'fum'
183
- complete true
554
+ context 'types' do
555
+ it 'chef_node with attribute a, true sets a to true' do
556
+ run_recipe do
557
+ chef_node 'blah' do
558
+ attribute 'a', true
559
+ end
560
+ end
561
+ expect(get('nodes/blah')).to include(
562
+ 'normal' => {
563
+ 'a' => true,
564
+ 'c' => { 'd' => 'e' },
565
+ 'tags' => [ 'a', 'b' ]
566
+ },
567
+ 'automatic' => { 'x' => 'y' },
568
+ 'chef_environment' => 'desert'
569
+ )
570
+ end
571
+
572
+ it 'chef_node with attribute a, 1 sets a to 1' do
573
+ run_recipe do
574
+ chef_node 'blah' do
575
+ attribute 'a', 1
576
+ end
577
+ end
578
+ expect(get('nodes/blah')).to include(
579
+ 'normal' => {
580
+ 'a' => 1,
581
+ 'c' => { 'd' => 'e' },
582
+ 'tags' => [ 'a', 'b' ]
583
+ },
584
+ 'automatic' => { 'x' => 'y' },
585
+ 'chef_environment' => 'desert'
586
+ )
587
+ end
588
+
589
+ it 'chef_node with attribute a, "1" sets a to "1"' do
590
+ run_recipe do
591
+ chef_node 'blah' do
592
+ attribute 'a', "1"
593
+ end
594
+ end
595
+ expect(get('nodes/blah')).to include(
596
+ 'normal' => {
597
+ 'a' => "1",
598
+ 'c' => { 'd' => 'e' },
599
+ 'tags' => [ 'a', 'b' ]
600
+ },
601
+ 'automatic' => { 'x' => 'y' },
602
+ 'chef_environment' => 'desert'
603
+ )
604
+ end
605
+
606
+ it 'chef_node with attribute a, "" sets a to ""' do
607
+ run_recipe do
608
+ chef_node 'blah' do
609
+ attribute 'a', ""
610
+ end
611
+ end
612
+ expect(get('nodes/blah')).to include(
613
+ 'normal' => {
614
+ 'a' => "",
615
+ 'c' => { 'd' => 'e' },
616
+ 'tags' => [ 'a', 'b' ]
617
+ },
618
+ 'automatic' => { 'x' => 'y' },
619
+ 'chef_environment' => 'desert'
620
+ )
621
+ end
622
+
623
+ it 'chef_node with attribute a, nil sets a to nil' do
624
+ run_recipe do
625
+ chef_node 'blah' do
626
+ attribute 'a', nil
627
+ end
628
+ end
629
+ expect(get('nodes/blah')).to include(
630
+ 'normal' => {
631
+ 'a' => nil,
632
+ 'c' => { 'd' => 'e' },
633
+ 'tags' => [ 'a', 'b' ]
634
+ },
635
+ 'automatic' => { 'x' => 'y' },
636
+ 'chef_environment' => 'desert'
637
+ )
184
638
  end
185
639
  end
186
640
 
187
- it 'normal foo attribute is replaced with new attribute' do
188
- expect(chef_run).to have_updated 'chef_node[blah]', :create
189
- node = get('nodes/blah')
190
- expect(node['normal']).to eq({ 'foe' => 'fum', 'tags' => [ 'a', 'b' ] })
641
+ context 'multiple attribute definitions' do
642
+ it 'chef_node with attribute a, x and c, y replaces both attributes' do
643
+ run_recipe do
644
+ chef_node 'blah' do
645
+ attribute 'a', 'x'
646
+ attribute 'c', 'y'
647
+ end
648
+ end
649
+ expect(get('nodes/blah')).to include(
650
+ 'normal' => {
651
+ 'a' => 'x',
652
+ 'c' => 'y',
653
+ 'tags' => [ 'a', 'b' ]
654
+ },
655
+ 'automatic' => { 'x' => 'y' },
656
+ 'chef_environment' => 'desert'
657
+ )
658
+ end
659
+
660
+ it 'chef_node with attribute m, x and n, y adds both attributes' do
661
+ run_recipe do
662
+ chef_node 'blah' do
663
+ attribute 'm', 'x'
664
+ attribute 'n', 'y'
665
+ end
666
+ end
667
+ expect(get('nodes/blah')).to include(
668
+ 'normal' => {
669
+ 'a' => 'b',
670
+ 'c' => { 'd' => 'e' },
671
+ 'm' => 'x',
672
+ 'n' => 'y',
673
+ 'tags' => [ 'a', 'b' ]
674
+ },
675
+ 'automatic' => { 'x' => 'y' },
676
+ 'chef_environment' => 'desert'
677
+ )
678
+ end
679
+
680
+ it 'chef_node with attribute [x, y], z and [x, yy], zz adds both attributes' do
681
+ run_recipe do
682
+ chef_node 'blah' do
683
+ attribute [ 'x', 'y' ], 'z'
684
+ attribute [ 'x', 'yy' ], 'zz'
685
+ end
686
+ end
687
+ expect(get('nodes/blah')).to include(
688
+ 'normal' => {
689
+ 'a' => 'b',
690
+ 'c' => { 'd' => 'e' },
691
+ 'x' => {
692
+ 'y' => 'z',
693
+ 'yy' => 'zz'
694
+ },
695
+ 'tags' => [ 'a', 'b' ]
696
+ },
697
+ 'automatic' => { 'x' => 'y' },
698
+ 'chef_environment' => 'desert'
699
+ )
700
+ end
701
+
702
+ describe 'precedence' do
703
+ it 'chef_node with attribute a, 1 and a, 2 sets a to 2' do
704
+ run_recipe do
705
+ chef_node 'blah' do
706
+ attribute 'a', 1
707
+ attribute 'a', 2
708
+ end
709
+ end
710
+ expect(get('nodes/blah')).to include(
711
+ 'normal' => {
712
+ 'a' => 2,
713
+ 'c' => { 'd' => 'e' },
714
+ 'tags' => [ 'a', 'b' ]
715
+ },
716
+ 'automatic' => { 'x' => 'y' },
717
+ 'chef_environment' => 'desert'
718
+ )
719
+ end
720
+
721
+ it 'chef_node with attribute [ x, y ], 1 and [ x, y ], 2 sets [ x, y ], 2' do
722
+ run_recipe do
723
+ chef_node 'blah' do
724
+ attribute [ 'x', 'y' ], 1
725
+ attribute [ 'x', 'y' ], 2
726
+ end
727
+ end
728
+ expect(get('nodes/blah')).to include(
729
+ 'normal' => {
730
+ 'a' => 'b',
731
+ 'c' => { 'd' => 'e' },
732
+ 'x' => { 'y' => 2 },
733
+ 'tags' => [ 'a', 'b' ]
734
+ },
735
+ 'automatic' => { 'x' => 'y' },
736
+ 'chef_environment' => 'desert'
737
+ )
738
+ end
739
+
740
+ it 'chef_node with attribute [ c, e ], { a => 1 }, [ c, e ], { b => 2 } sets b only' do
741
+ run_recipe do
742
+ chef_node 'blah' do
743
+ attribute [ 'c', 'e' ], { 'a' => 1 }
744
+ attribute [ 'c', 'e' ], { 'b' => 2 }
745
+ end
746
+ end
747
+ expect(get('nodes/blah')).to include(
748
+ 'normal' => {
749
+ 'a' => 'b',
750
+ 'c' => { 'd' => 'e', 'e' => { 'b' => 2 } },
751
+ 'tags' => [ 'a', 'b' ]
752
+ },
753
+ 'automatic' => { 'x' => 'y' },
754
+ 'chef_environment' => 'desert'
755
+ )
756
+ end
757
+
758
+ it 'chef_node with attribute [ c, e ], { a => 1 }, [ c, e, b ], 2 sets both' do
759
+ run_recipe do
760
+ chef_node 'blah' do
761
+ attribute [ 'c', 'e' ], { 'a' => 1 }
762
+ attribute [ 'c', 'e', 'b' ], 2
763
+ end
764
+ end
765
+ expect(get('nodes/blah')).to include(
766
+ 'normal' => {
767
+ 'a' => 'b',
768
+ 'c' => { 'd' => 'e', 'e' => { 'a' => 1, 'b' => 2 } },
769
+ 'tags' => [ 'a', 'b' ]
770
+ },
771
+ 'automatic' => { 'x' => 'y' },
772
+ 'chef_environment' => 'desert'
773
+ )
774
+ end
775
+
776
+ it 'chef_node with attribute [ c, e, b ], 2, [ c, e ], { a => 1 } sets a only' do
777
+ run_recipe do
778
+ chef_node 'blah' do
779
+ attribute [ 'c', 'e', 'b' ], 2
780
+ attribute [ 'c', 'e' ], { 'a' => 1 }
781
+ end
782
+ end
783
+ expect(get('nodes/blah')).to include(
784
+ 'normal' => {
785
+ 'a' => 'b',
786
+ 'c' => { 'd' => 'e', 'e' => { 'a' => 1 } },
787
+ 'tags' => [ 'a', 'b' ]
788
+ },
789
+ 'automatic' => { 'x' => 'y' },
790
+ 'chef_environment' => 'desert'
791
+ )
792
+ end
793
+ end
191
794
  end
192
795
  end
193
-
194
796
  end
195
797
  end
196
798