hiera 0.3.0 → 1.0.0rc4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of hiera might be problematic. Click here for more details.
- data/CHANGELOG +112 -0
- data/COPYING +202 -0
- data/README.md +237 -0
- data/bin/hiera +160 -156
- data/lib/hiera.rb +58 -50
- data/lib/hiera/backend.rb +174 -161
- data/lib/hiera/backend/yaml_backend.rb +67 -45
- data/lib/hiera/config.rb +43 -41
- data/lib/hiera/console_logger.rb +9 -9
- data/lib/hiera/noop_logger.rb +8 -0
- data/lib/hiera/puppet_logger.rb +10 -5
- data/lib/hiera/util.rb +47 -0
- data/spec/spec_helper.rb +42 -6
- data/spec/unit/backend/yaml_backend_spec.rb +153 -104
- data/spec/unit/backend_spec.rb +309 -255
- data/spec/unit/config_spec.rb +85 -79
- data/spec/unit/console_logger_spec.rb +13 -13
- data/spec/unit/hiera_spec.rb +57 -54
- data/spec/unit/util_spec.rb +49 -0
- metadata +21 -10
data/spec/unit/config_spec.rb
CHANGED
@@ -1,84 +1,90 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class Hiera
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Config.expects(:require).with("hiera/backend/two_backend")
|
63
|
-
Config.load_backends
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should warn if it cant load a backend" do
|
67
|
-
Config.load(:backends => ["one"])
|
68
|
-
Config.expects(:require).with("hiera/backend/one_backend").raises("fail")
|
69
|
-
|
70
|
-
expect {
|
71
|
-
Config.load_backends
|
72
|
-
}.to raise_error("fail")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#include?" do
|
77
|
-
it "should correctly report inclusion" do
|
78
|
-
Config.load({})
|
79
|
-
Config.include?(:foo).should == false
|
80
|
-
Config.include?(:logger).should == true
|
81
|
-
end
|
82
|
-
end
|
4
|
+
describe Config do
|
5
|
+
describe "#load" do
|
6
|
+
let(:default_config) do
|
7
|
+
{
|
8
|
+
:backends => ["yaml"],
|
9
|
+
:hierarchy => "common",
|
10
|
+
:logger => "console"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should treat string sources as a filename" do
|
15
|
+
expect { Config.load("/nonexisting") }.should raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should raise an error for missing config files" do
|
19
|
+
File.expects(:exist?).with("/nonexisting").returns(false)
|
20
|
+
YAML.expects(:load_file).with("/nonexisting").never
|
21
|
+
|
22
|
+
expect { Config.load("/nonexisting") }.should raise_error "Config file /nonexisting not found"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should attempt to YAML load config files" do
|
26
|
+
File.expects(:exist?).with("/nonexisting").returns(true)
|
27
|
+
YAML.expects(:load_file).with("/nonexisting").returns(YAML.load("---\n"))
|
28
|
+
|
29
|
+
Config.load("/nonexisting")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should use defaults on empty YAML config file" do
|
33
|
+
File.expects(:exist?).with("/nonexisting").returns(true)
|
34
|
+
YAML.expects(:load_file).with("/nonexisting").returns(YAML.load(""))
|
35
|
+
|
36
|
+
Config.load("/nonexisting").should == default_config
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use hash data as source if supplied" do
|
40
|
+
config = Config.load({"rspec" => "test"})
|
41
|
+
config["rspec"].should == "test"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should merge defaults with the loaded or supplied config" do
|
45
|
+
config = Config.load({})
|
46
|
+
config.should == {:backends => ["yaml"], :hierarchy => "common", :logger => "console"}
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should force :backends to be a flattened array" do
|
50
|
+
Config.load({:backends => [["foo", ["bar"]]]}).should == {:backends => ["foo", "bar"], :hierarchy => "common", :logger => "console"}
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should load the supplied logger" do
|
54
|
+
Hiera.expects(:logger=).with("foo")
|
55
|
+
Config.load({:logger => "foo"})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should default to the console logger" do
|
59
|
+
Hiera.expects(:logger=).with("console")
|
60
|
+
Config.load({})
|
61
|
+
end
|
83
62
|
end
|
63
|
+
|
64
|
+
describe "#load_backends" do
|
65
|
+
it "should load each backend" do
|
66
|
+
Config.load(:backends => ["One", "Two"])
|
67
|
+
Config.expects(:require).with("hiera/backend/one_backend")
|
68
|
+
Config.expects(:require).with("hiera/backend/two_backend")
|
69
|
+
Config.load_backends
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should warn if it cant load a backend" do
|
73
|
+
Config.load(:backends => ["one"])
|
74
|
+
Config.expects(:require).with("hiera/backend/one_backend").raises("fail")
|
75
|
+
|
76
|
+
expect {
|
77
|
+
Config.load_backends
|
78
|
+
}.to raise_error("fail")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#include?" do
|
83
|
+
it "should correctly report inclusion" do
|
84
|
+
Config.load({})
|
85
|
+
Config.include?(:foo).should == false
|
86
|
+
Config.include?(:logger).should == true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
84
90
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class Hiera
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
describe Console_logger do
|
5
|
+
describe "#warn" do
|
6
|
+
it "should warn to STDERR" do
|
7
|
+
STDERR.expects(:puts).with("WARN: 0: foo")
|
8
|
+
Time.expects(:now).returns(0)
|
9
|
+
Console_logger.warn("foo")
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
12
|
+
it "should debug to STDERR" do
|
13
|
+
STDERR.expects(:puts).with("DEBUG: 0: foo")
|
14
|
+
Time.expects(:now).returns(0)
|
15
|
+
Console_logger.debug("foo")
|
16
|
+
end
|
18
17
|
end
|
18
|
+
end
|
19
19
|
end
|
data/spec/unit/hiera_spec.rb
CHANGED
@@ -1,59 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'hiera/util'
|
2
3
|
|
3
4
|
describe "Hiera" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should fall back to the Console logger on failure" do
|
12
|
-
Hiera.expects(:warn).with("Failed to load foo logger: LoadError: no such file to load -- hiera/foo_logger")
|
13
|
-
Hiera.logger = "foo"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#warn" do
|
18
|
-
it "should call the supplied logger" do
|
19
|
-
Hiera::Console_logger.expects(:warn).with("rspec")
|
20
|
-
Hiera.warn("rspec")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#debug" do
|
25
|
-
it "should call the supplied logger" do
|
26
|
-
Hiera::Console_logger.expects(:debug).with("rspec")
|
27
|
-
Hiera.debug("rspec")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#initialize" do
|
32
|
-
it "should default to /etc/hiera.yaml for config" do
|
33
|
-
Hiera::Config.expects(:load).with("/etc/hiera.yaml")
|
34
|
-
Hiera::Config.stubs(:load_backends)
|
35
|
-
Hiera.new
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should pass the supplied config to the config class" do
|
39
|
-
Hiera::Config.expects(:load).with({"test" => "rspec"})
|
40
|
-
Hiera::Config.stubs(:load_backends)
|
41
|
-
Hiera.new(:config => {"test" => "rspec"})
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should load all backends on start" do
|
45
|
-
Hiera::Config.stubs(:load)
|
46
|
-
Hiera::Config.expects(:load_backends)
|
47
|
-
Hiera.new
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#lookup" do
|
52
|
-
it "should proxy to the Backend#lookup method" do
|
53
|
-
Hiera::Config.stubs(:load)
|
54
|
-
Hiera::Config.stubs(:load_backends)
|
55
|
-
Hiera::Backend.expects(:lookup).with(:key, :default, :scope, :order_override, :resolution_type)
|
56
|
-
Hiera.new.lookup(:key, :default, :scope, :order_override, :resolution_type)
|
57
|
-
end
|
5
|
+
describe "#logger=" do
|
6
|
+
it "should attempt to load the supplied logger" do
|
7
|
+
Hiera.stubs(:warn)
|
8
|
+
Hiera.expects(:require).with("hiera/foo_logger").raises("fail")
|
9
|
+
Hiera.logger = "foo"
|
58
10
|
end
|
11
|
+
|
12
|
+
it "should fall back to the Console logger on failure" do
|
13
|
+
Hiera.expects(:warn)
|
14
|
+
Hiera.logger = "foo"
|
15
|
+
Hiera.logger.should be Hiera::Console_logger
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#warn" do
|
20
|
+
it "should call the supplied logger" do
|
21
|
+
Hiera::Console_logger.expects(:warn).with("rspec")
|
22
|
+
Hiera.warn("rspec")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#debug" do
|
27
|
+
it "should call the supplied logger" do
|
28
|
+
Hiera::Console_logger.expects(:debug).with("rspec")
|
29
|
+
Hiera.debug("rspec")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#initialize" do
|
34
|
+
it "should use a default config" do
|
35
|
+
config_file = File.join(Hiera::Util.config_dir, 'hiera.yaml')
|
36
|
+
Hiera::Config.expects(:load).with(config_file)
|
37
|
+
Hiera::Config.stubs(:load_backends)
|
38
|
+
Hiera.new
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should pass the supplied config to the config class" do
|
42
|
+
Hiera::Config.expects(:load).with({"test" => "rspec"})
|
43
|
+
Hiera::Config.stubs(:load_backends)
|
44
|
+
Hiera.new(:config => {"test" => "rspec"})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should load all backends on start" do
|
48
|
+
Hiera::Config.stubs(:load)
|
49
|
+
Hiera::Config.expects(:load_backends)
|
50
|
+
Hiera.new
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#lookup" do
|
55
|
+
it "should proxy to the Backend#lookup method" do
|
56
|
+
Hiera::Config.stubs(:load)
|
57
|
+
Hiera::Config.stubs(:load_backends)
|
58
|
+
Hiera::Backend.expects(:lookup).with(:key, :default, :scope, :order_override, :resolution_type)
|
59
|
+
Hiera.new.lookup(:key, :default, :scope, :order_override, :resolution_type)
|
60
|
+
end
|
61
|
+
end
|
59
62
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hiera::Util do
|
4
|
+
describe 'Hiera::Util.posix?' do
|
5
|
+
it 'should return true on posix systems' do
|
6
|
+
Etc.expects(:getpwuid).with(0).returns(true)
|
7
|
+
Hiera::Util.posix?.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return false on non posix systems' do
|
11
|
+
Etc.expects(:getpwuid).with(0).returns(nil)
|
12
|
+
Hiera::Util.posix?.should be_false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'Hiera::Util.microsoft_windows?' do
|
17
|
+
it 'should return false on posix systems' do
|
18
|
+
Hiera::Util.expects(:file_alt_separator).returns(nil)
|
19
|
+
Hiera::Util.microsoft_windows?.should be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'Hiera::Util.config_dir' do
|
24
|
+
it 'should return the correct path for posix systems' do
|
25
|
+
Hiera::Util.expects(:file_alt_separator).returns(nil)
|
26
|
+
Hiera::Util.config_dir.should == '/etc'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return the correct path for microsoft windows systems' do
|
30
|
+
Hiera::Util.expects(:microsoft_windows?).returns(true)
|
31
|
+
Hiera::Util.expects(:common_appdata).returns('C:\\ProgramData')
|
32
|
+
Hiera::Util.config_dir.should == 'C:\\ProgramData/PuppetLabs/hiera/etc'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'Hiera::Util.var_dir' do
|
37
|
+
it 'should return the correct path for posix systems' do
|
38
|
+
Hiera::Util.expects(:file_alt_separator).returns(nil)
|
39
|
+
Hiera::Util.var_dir.should == '/var/lib/hiera'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return the correct path for microsoft windows systems' do
|
43
|
+
Hiera::Util.expects(:microsoft_windows?).returns(true)
|
44
|
+
Hiera::Util.expects(:common_appdata).returns('C:\\ProgramData')
|
45
|
+
Hiera::Util.var_dir.should == 'C:\\ProgramData/PuppetLabs/hiera/var'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: -1164341432
|
5
|
+
prerelease: 5
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
- 3
|
9
9
|
- 0
|
10
|
-
|
10
|
+
- rc
|
11
|
+
- 4
|
12
|
+
version: 1.0.0rc4
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- Puppet Labs
|
@@ -15,7 +17,7 @@ autorequire:
|
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2012-
|
20
|
+
date: 2012-07-20 00:00:00 Z
|
19
21
|
dependencies: []
|
20
22
|
|
21
23
|
description: A pluggable data store for hierarcical data
|
@@ -32,8 +34,13 @@ files:
|
|
32
34
|
- lib/hiera/backend.rb
|
33
35
|
- lib/hiera/config.rb
|
34
36
|
- lib/hiera/console_logger.rb
|
37
|
+
- lib/hiera/noop_logger.rb
|
35
38
|
- lib/hiera/puppet_logger.rb
|
39
|
+
- lib/hiera/util.rb
|
36
40
|
- lib/hiera.rb
|
41
|
+
- CHANGELOG
|
42
|
+
- COPYING
|
43
|
+
- README.md
|
37
44
|
- spec/spec.opts
|
38
45
|
- spec/spec_helper.rb
|
39
46
|
- spec/unit/backend/yaml_backend_spec.rb
|
@@ -41,6 +48,7 @@ files:
|
|
41
48
|
- spec/unit/config_spec.rb
|
42
49
|
- spec/unit/console_logger_spec.rb
|
43
50
|
- spec/unit/hiera_spec.rb
|
51
|
+
- spec/unit/util_spec.rb
|
44
52
|
homepage: https://github.com/puppetlabs/hiera/
|
45
53
|
licenses: []
|
46
54
|
|
@@ -61,16 +69,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
70
|
none: false
|
63
71
|
requirements:
|
64
|
-
- - "
|
72
|
+
- - ">"
|
65
73
|
- !ruby/object:Gem::Version
|
66
|
-
hash:
|
74
|
+
hash: 25
|
67
75
|
segments:
|
68
|
-
-
|
69
|
-
|
76
|
+
- 1
|
77
|
+
- 3
|
78
|
+
- 1
|
79
|
+
version: 1.3.1
|
70
80
|
requirements: []
|
71
81
|
|
72
82
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
83
|
+
rubygems_version: 1.8.24
|
74
84
|
signing_key:
|
75
85
|
specification_version: 3
|
76
86
|
summary: Light weight hierarcical data store
|
@@ -82,3 +92,4 @@ test_files:
|
|
82
92
|
- spec/unit/config_spec.rb
|
83
93
|
- spec/unit/console_logger_spec.rb
|
84
94
|
- spec/unit/hiera_spec.rb
|
95
|
+
- spec/unit/util_spec.rb
|