hiera 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,14 @@ require 'spec_helper'
2
2
  require 'hiera/util'
3
3
 
4
4
  class Hiera
5
+ module Backend
6
+ class Backend1x_backend
7
+ def lookup(key, scope, order_override, resolution_type)
8
+ ["a", "b"]
9
+ end
10
+ end
11
+ end
12
+
5
13
  describe Backend do
6
14
  describe "#datadir" do
7
15
  it "interpolates any values in the configured value" do
@@ -84,7 +92,7 @@ class Hiera
84
92
  end
85
93
 
86
94
  it "parses the names of the hierarchy levels using the given scope" do
87
- Backend.expects(:parse_string).with("common", {:rspec => :tests})
95
+ Backend.expects(:parse_string).with("common", {:rspec => :tests}, {}, {:order_override => nil})
88
96
  Backend.datasources({:rspec => :tests}) { }
89
97
  end
90
98
 
@@ -181,17 +189,6 @@ class Hiera
181
189
  "test_%{scope('rspec')}_test" => "test__test"
182
190
  }
183
191
 
184
- @interprets_undefined_in_scope_tests.each do |input, expected|
185
- it "interprets :undefined in scope as a non-value" do
186
- Backend.parse_string(input, {"rspec" => :undefined}).should == expected
187
- end
188
- end
189
-
190
- it "uses the value from extra_data when scope is :undefined" do
191
- input = "test_%{rspec}_test"
192
- Backend.parse_string(input, {"rspec" => :undefined}, { "rspec" => "extra" }).should == "test_extra_test"
193
- end
194
-
195
192
  @exact_lookup_tests = {
196
193
  "test_%{::rspec::data}_test" => "test_value_test",
197
194
  "test_%{scope('::rspec::data')}_test" => "test_value_test"
@@ -253,15 +250,32 @@ class Hiera
253
250
  end.to raise_error Hiera::InterpolationLoop, "Detected in [first, second]"
254
251
  end
255
252
 
253
+ it "replaces repeated occurances of the same lookup" do
254
+ scope = {"rspec" => "value"}
255
+ input = "it replaces %{rspec} and %{rspec}"
256
+ Backend.parse_string(input, scope).should == "it replaces value and value"
257
+ end
258
+
256
259
  it "replaces hiera interpolations with data looked up in hiera" do
257
260
  input = "%{hiera('key1')}"
258
261
  scope = {}
259
262
  Config.load({:yaml => {:datadir => "/tmp"}})
260
263
  Config.load_backends
261
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("key1", scope, nil, :priority).returns("answer")
264
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("key1", scope, nil, :priority, instance_of(Hash)).returns("answer")
262
265
 
263
266
  Backend.parse_string(input, scope).should == "answer"
264
267
  end
268
+
269
+ it "interpolation passes the order_override back into the backend" do
270
+ Backend.expects(:lookup).with("lookup::key", nil, {}, "order_override_datasource", :priority, instance_of(Hash))
271
+ Backend.parse_string("%{hiera('lookup::key')}", {}, {}, {:order_override => "order_override_datasource"})
272
+ end
273
+
274
+ it "replaces literal interpolations with their argument" do
275
+ scope = {}
276
+ input = "%{literal('%')}{rspec::data}"
277
+ Backend.parse_string(input, scope).should == "%{rspec::data}"
278
+ end
265
279
  end
266
280
 
267
281
  describe "#parse_answer" do
@@ -300,16 +314,47 @@ class Hiera
300
314
  scope = {}
301
315
  Config.load({:yaml => {:datadir => "/tmp"}})
302
316
  Config.load_backends
303
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("test")
317
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("test")
304
318
  Backend.parse_answer(input, scope).should == "test_test_test"
305
319
  end
306
320
 
321
+ it "interpolates alias lookups with non-string types" do
322
+ input = "%{alias('rspec')}"
323
+ scope = {}
324
+ Config.load({:yaml => {:datadir => "/tmp"}})
325
+ Config.load_backends
326
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns(['test', 'test'])
327
+ Backend.parse_answer(input, scope).should == ['test', 'test']
328
+ end
329
+
330
+ it 'fails if alias interpolation is attempted in a string context with a prefix' do
331
+ input = "stuff_before%{alias('rspec')}"
332
+ scope = {}
333
+ Config.load({:yaml => {:datadir => "/tmp"}})
334
+ Config.load_backends
335
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns(['test', 'test'])
336
+ expect do
337
+ Backend.parse_answer(input, scope).should == ['test', 'test']
338
+ end.to raise_error(Hiera::InterpolationInvalidValue, 'Cannot call alias in the string context')
339
+ end
340
+
341
+ it 'fails if alias interpolation is attempted in a string context with a postfix' do
342
+ input = "%{alias('rspec')}_stiff after"
343
+ scope = {}
344
+ Config.load({:yaml => {:datadir => "/tmp"}})
345
+ Config.load_backends
346
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns(['test', 'test'])
347
+ expect do
348
+ Backend.parse_answer(input, scope).should == ['test', 'test']
349
+ end.to raise_error(Hiera::InterpolationInvalidValue, 'Cannot call alias in the string context')
350
+ end
351
+
307
352
  it "interpolates hiera lookups in each string in an array" do
308
353
  input = ["test_%{hiera('rspec')}_test", "test_%{hiera('rspec')}_test", ["test_%{hiera('rspec')}_test"]]
309
354
  scope = {}
310
355
  Config.load({:yaml => {:datadir => "/tmp"}})
311
356
  Config.load_backends
312
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("test")
357
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("test")
313
358
  Backend.parse_answer(input, scope).should == ["test_test_test", "test_test_test", ["test_test_test"]]
314
359
  end
315
360
 
@@ -318,7 +363,7 @@ class Hiera
318
363
  scope = {}
319
364
  Config.load({:yaml => {:datadir => "/tmp"}})
320
365
  Config.load_backends
321
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("test")
366
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("test")
322
367
  Backend.parse_answer(input, scope).should == {"foo"=>"test_test_test", "bar"=>"test_test_test"}
323
368
  end
324
369
 
@@ -327,7 +372,7 @@ class Hiera
327
372
  scope = {}
328
373
  Config.load({:yaml => {:datadir => "/tmp"}})
329
374
  Config.load_backends
330
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("foo")
375
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("foo")
331
376
  Backend.parse_answer(input, scope).should == {"foo"=>"test"}
332
377
  end
333
378
 
@@ -336,7 +381,7 @@ class Hiera
336
381
  scope = {}
337
382
  Config.load({:yaml => {:datadir => "/tmp"}})
338
383
  Config.load_backends
339
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("foo")
384
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("foo")
340
385
  Backend.parse_answer(input, scope).should == {"topkey"=>{"foo" => "test"}}
341
386
  end
342
387
 
@@ -345,7 +390,7 @@ class Hiera
345
390
  scope = {}
346
391
  Config.load({:yaml => {:datadir => "/tmp"}})
347
392
  Config.load_backends
348
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("test")
393
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("test")
349
394
  Backend.parse_answer(input, scope).should == {"foo"=>"test_test_test", "bar"=>["test_test_test", "test_test_test"]}
350
395
  end
351
396
 
@@ -354,7 +399,7 @@ class Hiera
354
399
  scope = {"rspec2" => "scope_rspec"}
355
400
  Config.load({:yaml => {:datadir => "/tmp"}})
356
401
  Config.load_backends
357
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("hiera_rspec")
402
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("hiera_rspec")
358
403
  Backend.parse_answer(input, scope).should == {"foo"=>"test_hiera_rspec_test", "bar"=>"test_scope_rspec_test"}
359
404
  end
360
405
 
@@ -363,7 +408,7 @@ class Hiera
363
408
  scope = {"rspec" => "scope_rspec"}
364
409
  Config.load({:yaml => {:datadir => "/tmp"}})
365
410
  Config.load_backends
366
- Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority).returns("hiera_rspec")
411
+ Backend::Yaml_backend.any_instance.stubs(:lookup).with("rspec", scope, nil, :priority, instance_of(Hash)).returns("hiera_rspec")
367
412
  Backend.parse_answer(input, scope).should == "test_hiera_rspec_test_scope_rspec"
368
413
  end
369
414
 
@@ -425,7 +470,7 @@ class Hiera
425
470
  Config.load({:yaml => {:datadir => "/tmp"}})
426
471
  Config.load_backends
427
472
 
428
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil).returns("answer")
473
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil, instance_of(Hash)).returns("answer")
429
474
 
430
475
  Backend.lookup("key", "default", {}, nil, nil).should == "answer"
431
476
  end
@@ -434,9 +479,9 @@ class Hiera
434
479
  Config.load({:yaml => {:datadir => "/tmp"}})
435
480
  Config.load_backends
436
481
 
437
- Backend::Yaml_backend.any_instance.expects(:lookup).with("stringval", {}, nil, nil).returns("string")
438
- Backend::Yaml_backend.any_instance.expects(:lookup).with("boolval", {}, nil, nil).returns(false)
439
- Backend::Yaml_backend.any_instance.expects(:lookup).with("numericval", {}, nil, nil).returns(1)
482
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("stringval", {}, nil, nil, instance_of(Hash)).returns("string")
483
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("boolval", {}, nil, nil, instance_of(Hash)).returns(false)
484
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("numericval", {}, nil, nil, instance_of(Hash)).returns(1)
440
485
 
441
486
  Backend.lookup("stringval", "default", {}, nil, nil).should == "string"
442
487
  Backend.lookup("boolval", "default", {}, nil, nil).should == false
@@ -518,7 +563,7 @@ class Hiera
518
563
  Config.load_backends
519
564
 
520
565
  Backend.expects(:resolve_answer).with("test_test", :priority).returns("parsed")
521
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, :priority).returns("test_test")
566
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, :priority, instance_of(Hash)).returns("test_test")
522
567
 
523
568
  Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, :priority).should == "parsed"
524
569
  end
@@ -527,31 +572,129 @@ class Hiera
527
572
  Config.load({:yaml => {:datadir => "/tmp"}})
528
573
  Config.load_backends
529
574
 
530
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, nil)
575
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, nil, instance_of(Hash)).throws(:no_such_key)
531
576
 
532
577
  Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == "test_test"
533
578
  end
534
579
 
580
+ it "returns nil instead of the default when key is found with a nil value" do
581
+ Config.load({:yaml => {:datadir => "/tmp"}})
582
+ Config.load_backends
583
+
584
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, nil, instance_of(Hash)).returns(nil)
585
+
586
+ Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == nil
587
+ end
588
+
535
589
  it "keeps string default data as a string" do
536
590
  Config.load({:yaml => {:datadir => "/tmp"}})
537
591
  Config.load_backends
538
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil)
592
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil, instance_of(Hash)).throws(:no_such_key)
539
593
  Backend.lookup("key", "test", {}, nil, nil).should == "test"
540
594
  end
541
595
 
542
596
  it "keeps array default data as an array" do
543
597
  Config.load({:yaml => {:datadir => "/tmp"}})
544
598
  Config.load_backends
545
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :array)
599
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :array, instance_of(Hash)).throws(:no_such_key)
546
600
  Backend.lookup("key", ["test"], {}, nil, :array).should == ["test"]
547
601
  end
548
602
 
549
603
  it "keeps hash default data as a hash" do
550
604
  Config.load({:yaml => {:datadir => "/tmp"}})
551
605
  Config.load_backends
552
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :hash)
606
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :hash, instance_of(Hash)).throws(:no_such_key)
553
607
  Backend.lookup("key", {"test" => "value"}, {}, nil, :hash).should == {"test" => "value"}
554
608
  end
609
+
610
+ it 'can use qualified key to lookup value in hash' do
611
+ Config.load({:yaml => {:datadir => '/tmp'}})
612
+ Config.load_backends
613
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns({ 'test' => 'value'})
614
+ Backend.lookup('key.test', 'dflt', {}, nil, nil).should == 'value'
615
+ end
616
+
617
+ it 'can use qualified key to lookup value in array' do
618
+ Config.load({:yaml => {:datadir => '/tmp'}})
619
+ Config.load_backends
620
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns([ 'first', 'second'])
621
+ Backend.lookup('key.1', 'dflt', {}, nil, nil).should == 'second'
622
+ end
623
+
624
+ it 'will fail when qualified key is partially found but not expected hash' do
625
+ Config.load({:yaml => {:datadir => '/tmp'}})
626
+ Config.load_backends
627
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns(['value 1', 'value 2'])
628
+ expect do
629
+ Backend.lookup('key.test', 'dflt', {}, nil, nil)
630
+ end.to raise_error(Exception, /^Hiera type mismatch:/)
631
+ end
632
+
633
+ it 'will fail when qualified key used with resolution_type :hash' do
634
+ expect do
635
+ Backend.lookup('key.test', 'dflt', {}, nil, :hash)
636
+ end.to raise_error(ArgumentError, /^Resolution type :hash is illegal/)
637
+ end
638
+
639
+ it 'will fail when qualified key used with resolution_type :array' do
640
+ expect do
641
+ Backend.lookup('key.test', 'dflt', {}, nil, :array)
642
+ end.to raise_error(ArgumentError, /^Resolution type :array is illegal/)
643
+ end
644
+
645
+ it 'will succeed when qualified key used with resolution_type :priority' do
646
+ Config.load({:yaml => {:datadir => '/tmp'}})
647
+ Config.load_backends
648
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, :priority, instance_of(Hash)).returns({ 'test' => 'value'})
649
+ Backend.lookup('key.test', 'dflt', {}, nil, :priority).should == 'value'
650
+ end
651
+
652
+ it 'will fail when qualified key is partially found but not expected array' do
653
+ Config.load({:yaml => {:datadir => '/tmp'}})
654
+ Config.load_backends
655
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns({ 'test' => 'value'})
656
+ expect do
657
+ Backend.lookup('key.2', 'dflt', {}, nil, nil)
658
+ end.to raise_error(Exception, /^Hiera type mismatch:/)
659
+ end
660
+
661
+ it 'will not fail when qualified key is partially not found' do
662
+ Config.load({:yaml => {:datadir => '/tmp'}})
663
+ Config.load_backends
664
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns(nil)
665
+ Backend.lookup('key.test', 'dflt', {}, nil, nil).should == 'dflt'
666
+ end
667
+
668
+ it 'will not fail when qualified key is array index out of bounds' do
669
+ Config.load({:yaml => {:datadir => '/tmp'}})
670
+ Config.load_backends
671
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', {}, nil, nil, instance_of(Hash)).returns(['value 1', 'value 2'])
672
+ Backend.lookup('key.33', 'dflt', {}, nil, nil).should == 'dflt'
673
+ end
674
+
675
+ it 'can use qualified key in interpolation to lookup value in hash' do
676
+ Config.load({:yaml => {:datadir => '/tmp'}})
677
+ Config.load_backends
678
+ Hiera::Backend.stubs(:datasourcefiles).yields('foo', 'bar')
679
+ Hiera::Filecache.any_instance.expects(:read_file).at_most(2).returns({'key' => '%{hiera(\'some.subkey\')}', 'some' => { 'subkey' => 'value' }})
680
+ Backend.lookup('key', 'dflt', {}, nil, nil).should == 'value'
681
+ end
682
+
683
+ it 'can use qualified key in interpolated default and scope' do
684
+ Config.load({:yaml => {:datadir => '/tmp'}})
685
+ Config.load_backends
686
+ scope = { 'some' => { 'test' => 'value'}}
687
+ Backend::Yaml_backend.any_instance.expects(:lookup).with('key', scope, nil, nil, instance_of(Hash))
688
+ Backend.lookup('key.notfound', '%{some.test}', scope, nil, nil).should == 'value'
689
+ end
690
+
691
+ it "handles older backend with 4 argument lookup" do
692
+ Config.load({})
693
+ Config.instance_variable_set("@config", {:backends => ["Backend1x"]})
694
+
695
+ Hiera.expects(:debug).at_least_once.with(regexp_matches /Using Hiera 1.x backend/)
696
+ Backend.lookup("key", {}, {"rspec" => "test"}, nil, :priority).should == ["a", "b"]
697
+ end
555
698
  end
556
699
 
557
700
  describe '#merge_answer' do
@@ -569,13 +712,30 @@ class Hiera
569
712
 
570
713
  it "uses deep_merge! when configured with :merge_behavior => :deeper" do
571
714
  Config.load({:merge_behavior => :deeper})
572
- Hash.any_instance.expects('deep_merge!').with({"b" => "bnswer"}).returns({"a" => "answer", "b" => "bnswer"})
715
+ Hash.any_instance.expects('deep_merge!').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
573
716
  Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"}).should == {"a" => "answer", "b" => "bnswer"}
574
717
  end
575
718
 
576
719
  it "uses deep_merge when configured with :merge_behavior => :deep" do
577
720
  Config.load({:merge_behavior => :deep})
578
- Hash.any_instance.expects('deep_merge').with({"b" => "bnswer"}).returns({"a" => "answer", "b" => "bnswer"})
721
+ Hash.any_instance.expects('deep_merge').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
722
+ Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"}).should == {"a" => "answer", "b" => "bnswer"}
723
+ end
724
+
725
+ it "disregards configuration when 'merge' parameter is given as a Hash" do
726
+ Config.load({:merge_behavior => :deep})
727
+ Hash.any_instance.expects('deep_merge!').with({"b" => "bnswer"}, {}).returns({"a" => "answer", "b" => "bnswer"})
728
+ Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"}, {:behavior => 'deeper' }).should == {"a" => "answer", "b" => "bnswer"}
729
+ end
730
+
731
+ it "propagates deep merge options when given Hash 'merge' parameter" do
732
+ Hash.any_instance.expects('deep_merge!').with({"b" => "bnswer"}, { :knockout_prefix => '-' }).returns({"a" => "answer", "b" => "bnswer"})
733
+ Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"}, {:behavior => 'deeper', :knockout_prefix => '-'}).should == {"a" => "answer", "b" => "bnswer"}
734
+ end
735
+
736
+ it "passes Config[:deep_merge_options] into calls to deep_merge" do
737
+ Config.load({:merge_behavior => :deep, :deep_merge_options => { :knockout_prefix => '-' } })
738
+ Hash.any_instance.expects('deep_merge').with({"b" => "bnswer"}, {:knockout_prefix => '-'}).returns({"a" => "answer", "b" => "bnswer"})
579
739
  Backend.merge_answer({"a" => "answer"},{"b" => "bnswer"}).should == {"a" => "answer", "b" => "bnswer"}
580
740
  end
581
741
  end
@@ -61,7 +61,7 @@ class Hiera
61
61
  Config.load({})
62
62
  end
63
63
 
64
- context "loading '/dev/null' as spec tests do" do
64
+ context "loading '/dev/null' as spec tests do", :unless => Hiera::Util.microsoft_windows? do
65
65
  before :each do
66
66
  # Simulate the behavior of YAML.load_file('/dev/null') in MRI 1.9.3p194
67
67
  Config.stubs(:yaml_load_file).
@@ -69,7 +69,22 @@ class Hiera
69
69
  end
70
70
 
71
71
  it "is not exceptional behavior" do
72
- expect { Config.load('/dev/null') }.to_not raise_error
72
+ Config.load('/dev/null')
73
+ end
74
+ end
75
+
76
+ describe "if deep_merge can't be loaded" do
77
+ let(:error_message) { "Must have 'deep_merge' gem installed for the configured merge_behavior." }
78
+ before(:each) do
79
+ Config.expects(:require).with("deep_merge").raises(LoadError, "unable to load")
80
+ end
81
+
82
+ it "should error if merge_behavior is 'deep'" do
83
+ expect { Config.load(:merge_behavior => :deep) }.to raise_error(Hiera::Error, error_message)
84
+ end
85
+
86
+ it "should error if merge_behavior is 'deeper'" do
87
+ expect { Config.load(:merge_behavior => :deeper) }.to raise_error(Hiera::Error, error_message)
73
88
  end
74
89
  end
75
90
  end
@@ -0,0 +1,6 @@
1
+ :backends:
2
+ - yaml
3
+
4
+ :hierarchy:
5
+ - recursive
6
+ - niltest
@@ -0,0 +1,2 @@
1
+ niltest: 'Missing key #%{hiera("knotfound")}#. Key with nil #%{hiera("knil")}#'
2
+ knil: null
@@ -0,0 +1,3 @@
1
+ foo: '%{hiera("bar")}'
2
+
3
+ bar: '%{hiera("foo")}'
@@ -0,0 +1,5 @@
1
+ :backends:
2
+ - yaml
3
+
4
+ :hierarchy:
5
+ - common
@@ -0,0 +1 @@
1
+ bar: 'alternate'
@@ -0,0 +1,2 @@
1
+ foo: '%{hiera("bar")}'
2
+ bar: 'common'
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'hiera/util'
3
+
4
+ describe "Hiera" do
5
+ context "when doing interpolation" do
6
+ let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'interpolate') }
7
+
8
+ it 'should prevent endless recursion' do
9
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
10
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
11
+ expect do
12
+ hiera.lookup('foo', nil, {})
13
+ end.to raise_error Hiera::InterpolationLoop, 'Detected in [hiera("bar"), hiera("foo")]'
14
+ end
15
+ end
16
+
17
+ context "when not finding value for interpolated key" do
18
+ let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'interpolate') }
19
+
20
+ it 'should resolve the interpolation to an empty string' do
21
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
22
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
23
+ expect(hiera.lookup('niltest', nil, {})).to eq('Missing key ##. Key with nil ##')
24
+ end
25
+ end
26
+
27
+ context "when doing interpolation with override" do
28
+ let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'override') }
29
+
30
+ it 'should resolve interpolation using the override' do
31
+ Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
32
+ hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
33
+ expect(hiera.lookup('foo', nil, {}, 'alternate')).to eq('alternate')
34
+ end
35
+ end
36
+ end
@@ -23,26 +23,26 @@ describe Hiera::Util do
23
23
  describe 'Hiera::Util.config_dir' do
24
24
  it 'should return the correct path for posix systems' do
25
25
  Hiera::Util.expects(:file_alt_separator).returns(nil)
26
- Hiera::Util.config_dir.should == '/etc'
26
+ Hiera::Util.config_dir.should == '/etc/puppetlabs/code'
27
27
  end
28
28
 
29
29
  it 'should return the correct path for microsoft windows systems' do
30
30
  Hiera::Util.expects(:microsoft_windows?).returns(true)
31
31
  Hiera::Util.expects(:common_appdata).returns('C:\\ProgramData')
32
- Hiera::Util.config_dir.should == 'C:\\ProgramData/PuppetLabs/hiera/etc'
32
+ Hiera::Util.config_dir.should == 'C:\\ProgramData/PuppetLabs/code'
33
33
  end
34
34
  end
35
35
 
36
36
  describe 'Hiera::Util.var_dir' do
37
37
  it 'should return the correct path for posix systems' do
38
38
  Hiera::Util.expects(:file_alt_separator).returns(nil)
39
- Hiera::Util.var_dir.should == '/var/lib/hiera'
39
+ Hiera::Util.var_dir.should == '/etc/puppetlabs/code/hieradata'
40
40
  end
41
41
 
42
42
  it 'should return the correct path for microsoft windows systems' do
43
43
  Hiera::Util.expects(:microsoft_windows?).returns(true)
44
44
  Hiera::Util.expects(:common_appdata).returns('C:\\ProgramData')
45
- Hiera::Util.var_dir.should == 'C:\\ProgramData/PuppetLabs/hiera/var'
45
+ Hiera::Util.var_dir.should == 'C:\\ProgramData/PuppetLabs/code/hieradata'
46
46
  end
47
47
  end
48
48
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Puppet Labs
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2015-03-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json_pure
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: A pluggable data store for hierarcical data
@@ -35,70 +32,83 @@ extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
34
  - bin/hiera
38
- - lib/hiera/puppet_logger.rb
35
+ - lib/hiera/backend.rb
36
+ - lib/hiera/backend/json_backend.rb
37
+ - lib/hiera/backend/yaml_backend.rb
38
+ - lib/hiera/config.rb
39
39
  - lib/hiera/console_logger.rb
40
- - lib/hiera/filecache.rb
41
- - lib/hiera/version.rb
42
- - lib/hiera/fallback_logger.rb
43
40
  - lib/hiera/error.rb
41
+ - lib/hiera/fallback_logger.rb
42
+ - lib/hiera/filecache.rb
44
43
  - lib/hiera/interpolate.rb
45
- - lib/hiera/util.rb
46
- - lib/hiera/recursive_guard.rb
47
- - lib/hiera/backend.rb
48
44
  - lib/hiera/noop_logger.rb
49
- - lib/hiera/config.rb
50
- - lib/hiera/backend/yaml_backend.rb
51
- - lib/hiera/backend/json_backend.rb
45
+ - lib/hiera/puppet_logger.rb
46
+ - lib/hiera/recursive_guard.rb
47
+ - lib/hiera/util.rb
48
+ - lib/hiera/version.rb
52
49
  - lib/hiera.rb
53
50
  - COPYING
54
51
  - README.md
55
52
  - LICENSE
56
- - spec/unit/util_spec.rb
57
- - spec/unit/puppet_logger_spec.rb
58
- - spec/unit/version_spec.rb
59
- - spec/unit/config_spec.rb
53
+ - spec/spec_helper.rb
54
+ - spec/unit/backend/json_backend_spec.rb
55
+ - spec/unit/backend/yaml_backend_spec.rb
60
56
  - spec/unit/backend_spec.rb
61
- - spec/unit/filecache_spec.rb
62
- - spec/unit/hiera_spec.rb
57
+ - spec/unit/config_spec.rb
63
58
  - spec/unit/console_logger_spec.rb
64
- - spec/unit/backend/yaml_backend_spec.rb
65
- - spec/unit/backend/json_backend_spec.rb
66
59
  - spec/unit/fallback_logger_spec.rb
67
- - spec/spec_helper.rb
60
+ - spec/unit/filecache_spec.rb
61
+ - spec/unit/fixtures/interpolate/config/hiera.yaml
62
+ - spec/unit/fixtures/interpolate/data/niltest.yaml
63
+ - spec/unit/fixtures/interpolate/data/recursive.yaml
64
+ - spec/unit/fixtures/override/config/hiera.yaml
65
+ - spec/unit/fixtures/override/data/alternate.yaml
66
+ - spec/unit/fixtures/override/data/common.yaml
67
+ - spec/unit/hiera_spec.rb
68
+ - spec/unit/interpolate_spec.rb
69
+ - spec/unit/puppet_logger_spec.rb
70
+ - spec/unit/util_spec.rb
71
+ - spec/unit/version_spec.rb
68
72
  homepage: https://github.com/puppetlabs/hiera
69
73
  licenses: []
74
+ metadata: {}
70
75
  post_install_message:
71
76
  rdoc_options: []
72
77
  require_paths:
73
78
  - lib
74
79
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
80
  requirements:
77
- - - ! '>='
81
+ - - '>='
78
82
  - !ruby/object:Gem::Version
79
83
  version: '0'
80
84
  required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
85
  requirements:
83
- - - ! '>='
86
+ - - '>='
84
87
  - !ruby/object:Gem::Version
85
88
  version: '0'
86
89
  requirements: []
87
90
  rubyforge_project:
88
- rubygems_version: 1.8.23
91
+ rubygems_version: 2.0.14
89
92
  signing_key:
90
- specification_version: 3
93
+ specification_version: 4
91
94
  summary: Light weight hierarchical data store
92
95
  test_files:
93
- - spec/unit/util_spec.rb
94
- - spec/unit/puppet_logger_spec.rb
95
- - spec/unit/version_spec.rb
96
- - spec/unit/config_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/unit/backend/json_backend_spec.rb
98
+ - spec/unit/backend/yaml_backend_spec.rb
97
99
  - spec/unit/backend_spec.rb
98
- - spec/unit/filecache_spec.rb
99
- - spec/unit/hiera_spec.rb
100
+ - spec/unit/config_spec.rb
100
101
  - spec/unit/console_logger_spec.rb
101
- - spec/unit/backend/yaml_backend_spec.rb
102
- - spec/unit/backend/json_backend_spec.rb
103
102
  - spec/unit/fallback_logger_spec.rb
104
- - spec/spec_helper.rb
103
+ - spec/unit/filecache_spec.rb
104
+ - spec/unit/fixtures/interpolate/config/hiera.yaml
105
+ - spec/unit/fixtures/interpolate/data/niltest.yaml
106
+ - spec/unit/fixtures/interpolate/data/recursive.yaml
107
+ - spec/unit/fixtures/override/config/hiera.yaml
108
+ - spec/unit/fixtures/override/data/alternate.yaml
109
+ - spec/unit/fixtures/override/data/common.yaml
110
+ - spec/unit/hiera_spec.rb
111
+ - spec/unit/interpolate_spec.rb
112
+ - spec/unit/puppet_logger_spec.rb
113
+ - spec/unit/util_spec.rb
114
+ - spec/unit/version_spec.rb