hiera 1.3.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,6 +72,21 @@ class Hiera
72
72
  Config.load('/dev/null')
73
73
  end
74
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)
88
+ end
89
+ end
75
90
  end
76
91
 
77
92
  describe "#load_backends" do
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_pure
@@ -58,7 +58,14 @@ files:
58
58
  - spec/unit/console_logger_spec.rb
59
59
  - spec/unit/fallback_logger_spec.rb
60
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
61
67
  - spec/unit/hiera_spec.rb
68
+ - spec/unit/interpolate_spec.rb
62
69
  - spec/unit/puppet_logger_spec.rb
63
70
  - spec/unit/util_spec.rb
64
71
  - spec/unit/version_spec.rb
@@ -81,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
88
  version: '0'
82
89
  requirements: []
83
90
  rubyforge_project:
84
- rubygems_version: 2.0.3
91
+ rubygems_version: 2.0.14
85
92
  signing_key:
86
93
  specification_version: 4
87
94
  summary: Light weight hierarchical data store
@@ -94,7 +101,14 @@ test_files:
94
101
  - spec/unit/console_logger_spec.rb
95
102
  - spec/unit/fallback_logger_spec.rb
96
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
97
110
  - spec/unit/hiera_spec.rb
111
+ - spec/unit/interpolate_spec.rb
98
112
  - spec/unit/puppet_logger_spec.rb
99
113
  - spec/unit/util_spec.rb
100
114
  - spec/unit/version_spec.rb