hiera 0.2.0 → 0.3.0
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/bin/hiera +40 -1
- data/lib/hiera.rb +2 -4
- data/lib/hiera/backend.rb +14 -4
- data/lib/hiera/backend/yaml_backend.rb +8 -2
- data/lib/hiera/config.rb +2 -1
- data/spec/unit/backend/yaml_backend_spec.rb +85 -7
- data/spec/unit/backend_spec.rb +60 -2
- data/spec/unit/config_spec.rb +16 -2
- data/spec/unit/console_logger_spec.rb +1 -1
- data/spec/unit/hiera_spec.rb +1 -1
- metadata +25 -15
data/bin/hiera
CHANGED
@@ -61,12 +61,38 @@ def load_scope(source, type=:yaml)
|
|
61
61
|
|
62
62
|
# Puppet makes dumb yaml files that do not promote data reuse.
|
63
63
|
scope = scope.values if scope.is_a?(Puppet::Node::Facts)
|
64
|
+
|
64
65
|
when :json
|
65
66
|
raise "Cannot find scope #{type} file #{source}" unless File.exist?(source)
|
66
67
|
|
67
68
|
require 'json'
|
68
69
|
|
69
70
|
scope = JSON.load(File.read(source))
|
71
|
+
|
72
|
+
when :inventory_service
|
73
|
+
# For this to work the machine running the hiera command needs access to
|
74
|
+
# /facts REST endpoint on your inventory server. This access is
|
75
|
+
# controlled in auth.conf and identification is by the certname of the
|
76
|
+
# machine running hiera commands.
|
77
|
+
#
|
78
|
+
# Another caveat is that if your inventory server isn't at the short dns
|
79
|
+
# name of 'puppet' you will need to set the inventory_sever option in
|
80
|
+
# your puppet.conf. Set it in either the master or main sections. It
|
81
|
+
# is fine to have the inventory_server option set even if the config
|
82
|
+
# doesn't have the fact_terminus set to rest.
|
83
|
+
begin
|
84
|
+
require 'puppet/util/run_mode'
|
85
|
+
$puppet_application_mode = Puppet::Util::RunMode[:master]
|
86
|
+
require 'puppet'
|
87
|
+
Puppet.settings.parse
|
88
|
+
Puppet::Node::Facts.indirection.terminus_class = :rest
|
89
|
+
scope = YAML.load(Puppet::Node::Facts.indirection.find(source).to_yaml)
|
90
|
+
# Puppet makes dumb yaml files that do not promote data reuse.
|
91
|
+
scope = scope.values if scope.is_a?(Puppet::Node::Facts)
|
92
|
+
rescue Exception => e
|
93
|
+
STDERR.puts "Puppet inventory service lookup failed: #{e.class}: #{e}"
|
94
|
+
exit 1
|
95
|
+
end
|
70
96
|
else
|
71
97
|
raise "Don't know how to load data type #{type}"
|
72
98
|
end
|
@@ -90,6 +116,10 @@ OptionParser.new do |opts|
|
|
90
116
|
options[:resolution_type] = :array
|
91
117
|
end
|
92
118
|
|
119
|
+
opts.on("--hash", "-h", "Hash search") do
|
120
|
+
options[:resolution_type] = :hash
|
121
|
+
end
|
122
|
+
|
93
123
|
opts.on("--config CONFIG", "-c", "Configuration file") do |v|
|
94
124
|
if File.exist?(v)
|
95
125
|
options[:config] = v
|
@@ -110,7 +140,7 @@ OptionParser.new do |opts|
|
|
110
140
|
|
111
141
|
opts.on("--yaml SCOPE", "-y", "YAML format file to load scope from") do |v|
|
112
142
|
begin
|
113
|
-
options[:scope] = load_scope(v
|
143
|
+
options[:scope] = load_scope(v)
|
114
144
|
rescue Exception => e
|
115
145
|
STDERR.puts "Could not load YAML scope: #{e.class}: #{e}"
|
116
146
|
exit 1
|
@@ -125,6 +155,15 @@ OptionParser.new do |opts|
|
|
125
155
|
exit 1
|
126
156
|
end
|
127
157
|
end
|
158
|
+
|
159
|
+
opts.on("--inventory_service IDENTITY", "-i", "Retrieve facts for a node via Puppet's inventory service as scope") do |v|
|
160
|
+
begin
|
161
|
+
options[:scope] = load_scope(v, :inventory_service)
|
162
|
+
rescue Exception => e
|
163
|
+
STDERR.puts "Could not load Puppet inventory service scope: #{e.class}: #{e}"
|
164
|
+
exit 1
|
165
|
+
end
|
166
|
+
end
|
128
167
|
end.parse!
|
129
168
|
|
130
169
|
# arguments can be:
|
data/lib/hiera.rb
CHANGED
@@ -2,11 +2,12 @@ require 'rubygems'
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
class Hiera
|
5
|
-
VERSION = "0.
|
5
|
+
VERSION = "0.3.0"
|
6
6
|
|
7
7
|
autoload :Config, "hiera/config"
|
8
8
|
autoload :Backend, "hiera/backend"
|
9
9
|
autoload :Console_logger, "hiera/console_logger"
|
10
|
+
autoload :Puppet_logger, "hiera/puppet_logger"
|
10
11
|
|
11
12
|
class << self
|
12
13
|
def version
|
@@ -54,9 +55,6 @@ class Hiera
|
|
54
55
|
#
|
55
56
|
# The order-override will insert as first in the hierarchy a data source
|
56
57
|
# of your choice.
|
57
|
-
#
|
58
|
-
# TODO: resolution_type is to eventually support top down priority based
|
59
|
-
# lookups or bottom up merging type lookups like an ENC might need
|
60
58
|
def lookup(key, default, scope, order_override=nil, resolution_type=:priority)
|
61
59
|
Backend.lookup(key, default, scope, order_override, resolution_type)
|
62
60
|
end
|
data/lib/hiera/backend.rb
CHANGED
@@ -36,6 +36,8 @@ class Hiera
|
|
36
36
|
case resolution_type
|
37
37
|
when :array
|
38
38
|
return []
|
39
|
+
when :hash
|
40
|
+
return {}
|
39
41
|
else
|
40
42
|
return nil
|
41
43
|
end
|
@@ -65,7 +67,7 @@ class Hiera
|
|
65
67
|
|
66
68
|
hierarchy.flatten.map do |source|
|
67
69
|
source = parse_string(source, scope)
|
68
|
-
yield(source) unless source == ""
|
70
|
+
yield(source) unless source == "" or source =~ /(^\/|\/\/|\/$)/
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
@@ -103,7 +105,9 @@ class Hiera
|
|
103
105
|
# Ultimately it just pass the data through parse_string but
|
104
106
|
# it makes some effort to handle arrays of strings as well
|
105
107
|
def parse_answer(data, scope, extra_data={})
|
106
|
-
if data.is_a?(
|
108
|
+
if data.is_a?(Numeric) or data.is_a?(TrueClass) or data.is_a?(FalseClass)
|
109
|
+
return data
|
110
|
+
elsif data.is_a?(String)
|
107
111
|
return parse_string(data, scope, extra_data)
|
108
112
|
elsif data.is_a?(Hash)
|
109
113
|
answer = {}
|
@@ -125,7 +129,9 @@ class Hiera
|
|
125
129
|
def resolve_answer(answer, resolution_type)
|
126
130
|
case resolution_type
|
127
131
|
when :array
|
128
|
-
[answer].flatten.uniq.
|
132
|
+
[answer].flatten.uniq.compact
|
133
|
+
when :hash
|
134
|
+
answer # Hash structure should be preserved
|
129
135
|
else
|
130
136
|
answer
|
131
137
|
end
|
@@ -157,7 +163,11 @@ class Hiera
|
|
157
163
|
end
|
158
164
|
end
|
159
165
|
|
160
|
-
resolve_answer(answer, resolution_type)
|
166
|
+
answer = resolve_answer(answer, resolution_type)
|
167
|
+
answer = parse_string(default, scope) if answer.nil?
|
168
|
+
|
169
|
+
return default if answer == empty_answer(resolution_type)
|
170
|
+
return answer
|
161
171
|
end
|
162
172
|
end
|
163
173
|
end
|
@@ -19,6 +19,7 @@ class Hiera
|
|
19
19
|
|
20
20
|
data = YAML.load_file(yamlfile)
|
21
21
|
|
22
|
+
next if ! data
|
22
23
|
next if data.empty?
|
23
24
|
next unless data.include?(key)
|
24
25
|
|
@@ -27,11 +28,16 @@ class Hiera
|
|
27
28
|
# the array
|
28
29
|
#
|
29
30
|
# for priority searches we break after the first found data item
|
31
|
+
new_answer = Backend.parse_answer(data[key], scope)
|
30
32
|
case resolution_type
|
31
33
|
when :array
|
32
|
-
|
34
|
+
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
35
|
+
answer << new_answer
|
36
|
+
when :hash
|
37
|
+
raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
38
|
+
answer = new_answer.merge answer
|
33
39
|
else
|
34
|
-
answer =
|
40
|
+
answer = new_answer
|
35
41
|
break
|
36
42
|
end
|
37
43
|
end
|
data/lib/hiera/config.rb
CHANGED
@@ -12,7 +12,8 @@ class Hiera::Config
|
|
12
12
|
if source.is_a?(String)
|
13
13
|
raise "Config file #{source} not found" unless File.exist?(source)
|
14
14
|
|
15
|
-
|
15
|
+
config = YAML.load_file(source)
|
16
|
+
@config.merge! config if config
|
16
17
|
elsif source.is_a?(Hash)
|
17
18
|
@config.merge! source
|
18
19
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'hiera/backend/yaml_backend'
|
4
4
|
|
@@ -31,31 +31,109 @@ class Hiera
|
|
31
31
|
Backend.expects(:datasources).multiple_yields(["one"], ["two"])
|
32
32
|
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
33
33
|
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns(nil).never
|
34
|
-
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(
|
34
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load("---\nkey: answer"))
|
35
35
|
|
36
36
|
@backend.lookup("key", {}, nil, :priority).should == "answer"
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should not look up missing data files" do
|
40
|
+
Backend.expects(:datasources).multiple_yields(["one"])
|
41
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns(nil)
|
42
|
+
YAML.expects(:load_file).never
|
43
|
+
|
44
|
+
@backend.lookup("key", {}, nil, :priority)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return nil for empty data files" do
|
48
|
+
Backend.expects(:datasources).multiple_yields(["one"])
|
49
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
50
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load(""))
|
51
|
+
|
52
|
+
@backend.lookup("key", {}, nil, :priority).should be_nil
|
53
|
+
end
|
54
|
+
|
39
55
|
it "should build an array of all data sources for array searches" do
|
56
|
+
Backend.expects(:datasources).multiple_yields(["one"], ["two"])
|
40
57
|
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
41
58
|
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
42
59
|
|
60
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load("---\nkey: answer"))
|
61
|
+
YAML.expects(:load_file).with("/nonexisting/two.yaml").returns(YAML.load("---\nkey: answer"))
|
62
|
+
|
63
|
+
@backend.lookup("key", {}, nil, :array).should == ["answer", "answer"]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return empty hash of data sources for hash searches" do
|
67
|
+
Backend.expects(:datasources).multiple_yields(["one"])
|
68
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
69
|
+
|
70
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load(""))
|
71
|
+
|
72
|
+
@backend.lookup("key", {}, nil, :hash).should == {}
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should ignore empty hash of data sources for hash searches" do
|
43
76
|
Backend.expects(:datasources).multiple_yields(["one"], ["two"])
|
77
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
78
|
+
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
44
79
|
|
45
|
-
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(
|
46
|
-
YAML.expects(:load_file).with("/nonexisting/two.yaml").returns(
|
80
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load(""))
|
81
|
+
YAML.expects(:load_file).with("/nonexisting/two.yaml").returns(YAML.load("---\nkey:\n a: answer"))
|
47
82
|
|
48
|
-
@backend.lookup("key", {}, nil, :
|
83
|
+
@backend.lookup("key", {}, nil, :hash).should == {"a" => "answer"}
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should build a merged hash of data sources for hash searches" do
|
87
|
+
Backend.expects(:datasources).multiple_yields(["one"], ["two"])
|
88
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
89
|
+
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
90
|
+
|
91
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load("---\nkey:\n a: answer"))
|
92
|
+
YAML.expects(:load_file).with("/nonexisting/two.yaml").returns(YAML.load("---\nkey:\n a: wrong\n b: answer"))
|
93
|
+
|
94
|
+
@backend.lookup("key", {}, nil, :hash).should == {"a" => "answer", "b" => "answer"}
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should fail when trying to << a Hash" do
|
98
|
+
Backend.expects(:datasources).multiple_yields(["one"], ["two"])
|
99
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
100
|
+
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
101
|
+
|
102
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load("---\nkey:\n- a\n- answer"))
|
103
|
+
YAML.expects(:load_file).with("/nonexisting/two.yaml").returns(YAML.load("---\nkey:\n a: answer"))
|
104
|
+
|
105
|
+
lambda {@backend.lookup("key", {}, nil, :array)}.should raise_error(Exception, "Hiera type mismatch: expected Array and got Hash")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should fail when trying to merge an Array" do
|
109
|
+
Backend.expects(:datasources).multiple_yields(["one"], ["two"])
|
110
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
|
111
|
+
Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns("/nonexisting/two.yaml")
|
112
|
+
|
113
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load("---\nkey:\n a: answer"))
|
114
|
+
YAML.expects(:load_file).with("/nonexisting/two.yaml").returns(YAML.load("---\nkey:\n- a\n- wrong"))
|
115
|
+
|
116
|
+
lambda {@backend.lookup("key", {}, nil, :hash)}.should raise_error(Exception, "Hiera type mismatch: expected Hash and got Array")
|
49
117
|
end
|
50
118
|
|
51
119
|
it "should parse the answer for scope variables" do
|
52
120
|
Backend.expects(:datasources).yields("one")
|
53
121
|
Backend.expects(:datafile).with(:yaml, {"rspec" => "test"}, "one", "yaml").returns("/nonexisting/one.yaml")
|
54
|
-
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(
|
55
|
-
|
122
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load("---\nkey: 'test_%{rspec}'"))
|
56
123
|
|
57
124
|
@backend.lookup("key", {"rspec" => "test"}, nil, :priority).should == "test_test"
|
58
125
|
end
|
126
|
+
|
127
|
+
it "should retain datatypes found in yaml files" do
|
128
|
+
Backend.expects(:datasources).yields("one").times(3)
|
129
|
+
Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml").times(3)
|
130
|
+
|
131
|
+
YAML.expects(:load_file).with("/nonexisting/one.yaml").returns(YAML.load("---\nstringval: 'string'\nboolval: true\nnumericval: 1")).times(3)
|
132
|
+
|
133
|
+
@backend.lookup("stringval", {}, nil, :priority).should == "string"
|
134
|
+
@backend.lookup("boolval", {}, nil, :priority).should == true
|
135
|
+
@backend.lookup("numericval", {}, nil, :priority).should == 1
|
136
|
+
end
|
59
137
|
end
|
60
138
|
end
|
61
139
|
end
|
data/spec/unit/backend_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
class Hiera
|
4
4
|
describe Backend do
|
@@ -21,6 +21,10 @@ class Hiera
|
|
21
21
|
Backend.empty_answer(:array).should == []
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should return {} for hash searches" do
|
25
|
+
Backend.empty_answer(:hash).should == {}
|
26
|
+
end
|
27
|
+
|
24
28
|
it "should return nil otherwise" do
|
25
29
|
Backend.empty_answer(:meh).should == nil
|
26
30
|
end
|
@@ -152,11 +156,31 @@ class Hiera
|
|
152
156
|
input = {"foo" => "test_%{rspec}_test", "bar" => ["test_%{rspec}_test", "test_%{rspec}_test"]}
|
153
157
|
Backend.parse_answer(input, {"rspec" => "test"}).should == {"foo"=>"test_test_test", "bar"=>["test_test_test", "test_test_test"]}
|
154
158
|
end
|
159
|
+
|
160
|
+
it "should parse integers correctly" do
|
161
|
+
input = 1
|
162
|
+
Backend.parse_answer(input, {"rspec" => "test"}).should == 1
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should parse floats correctly" do
|
166
|
+
input = 0.233
|
167
|
+
Backend.parse_answer(input, {"rspec" => "test"}).should == 0.233
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should parse true boolean values correctly" do
|
171
|
+
input = true
|
172
|
+
Backend.parse_answer(input, {"rspec" => "test"}).should == true
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should parse false boolean values correctly" do
|
176
|
+
input = false
|
177
|
+
Backend.parse_answer(input, {"rspec" => "test"}).should == false
|
178
|
+
end
|
155
179
|
end
|
156
180
|
|
157
181
|
describe "#resolve_answer" do
|
158
182
|
it "should correctly parse array data" do
|
159
|
-
Backend.resolve_answer(["foo", ["foo", "foo"], "bar"], :array).should == ["
|
183
|
+
Backend.resolve_answer(["foo", ["foo", "foo"], "bar"], :array).should == ["foo", "bar"]
|
160
184
|
end
|
161
185
|
|
162
186
|
it "should just return the answer for non array data" do
|
@@ -189,6 +213,19 @@ class Hiera
|
|
189
213
|
Backend.lookup("key", "default", {}, nil, nil).should == "answer"
|
190
214
|
end
|
191
215
|
|
216
|
+
it "should retain the datatypes as returned by the backend" do
|
217
|
+
Config.load({:yaml => {:datadir => "/tmp"}})
|
218
|
+
Config.load_backends
|
219
|
+
|
220
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with("stringval", {}, nil, nil).returns("string")
|
221
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with("boolval", {}, nil, nil).returns(false)
|
222
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with("numericval", {}, nil, nil).returns(1)
|
223
|
+
|
224
|
+
Backend.lookup("stringval", "default", {}, nil, nil).should == "string"
|
225
|
+
Backend.lookup("boolval", "default", {}, nil, nil).should == false
|
226
|
+
Backend.lookup("numericval", "default", {}, nil, nil).should == 1
|
227
|
+
end
|
228
|
+
|
192
229
|
it "should call to all backends till an answer is found" do
|
193
230
|
backend = mock
|
194
231
|
backend.expects(:lookup).returns("answer")
|
@@ -220,6 +257,27 @@ class Hiera
|
|
220
257
|
|
221
258
|
Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == "test_test"
|
222
259
|
end
|
260
|
+
|
261
|
+
it "should correctly handle string default data" do
|
262
|
+
Config.load({:yaml => {:datadir => "/tmp"}})
|
263
|
+
Config.load_backends
|
264
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil)
|
265
|
+
Backend.lookup("key", "test", {}, nil, nil).should == "test"
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should correctly handle array default data" do
|
269
|
+
Config.load({:yaml => {:datadir => "/tmp"}})
|
270
|
+
Config.load_backends
|
271
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :array)
|
272
|
+
Backend.lookup("key", ["test"], {}, nil, :array).should == ["test"]
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should correctly handle hash default data" do
|
276
|
+
Config.load({:yaml => {:datadir => "/tmp"}})
|
277
|
+
Config.load_backends
|
278
|
+
Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :hash)
|
279
|
+
Backend.lookup("key", {"test" => "value"}, {}, nil, :hash).should == {"test" => "value"}
|
280
|
+
end
|
223
281
|
end
|
224
282
|
end
|
225
283
|
end
|
data/spec/unit/config_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
class Hiera
|
4
4
|
describe Config do
|
@@ -9,13 +9,27 @@ class Hiera
|
|
9
9
|
}.to raise_error("Config file /nonexisting not found")
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should raise error for missing config files" do
|
13
|
+
File.expects(:exist?).with("/nonexisting").returns(false)
|
14
|
+
YAML.expects(:load_file).with("/nonexisting").never
|
15
|
+
|
16
|
+
expect { Config.load("/nonexisting") }.should raise_error RuntimeError, /not found/
|
17
|
+
end
|
18
|
+
|
12
19
|
it "should attempt to YAML load config files" do
|
13
20
|
File.expects(:exist?).with("/nonexisting").returns(true)
|
14
|
-
YAML.expects(:load_file).with("/nonexisting").returns(
|
21
|
+
YAML.expects(:load_file).with("/nonexisting").returns(YAML.load("---\n"))
|
15
22
|
|
16
23
|
Config.load("/nonexisting")
|
17
24
|
end
|
18
25
|
|
26
|
+
it "should use defaults on empty YAML config file" do
|
27
|
+
File.expects(:exist?).with("/nonexisting").returns(true)
|
28
|
+
YAML.expects(:load_file).with("/nonexisting").returns(YAML.load(""))
|
29
|
+
|
30
|
+
Config.load("/nonexisting").should == {:backends => ["yaml"], :hierarchy => "common", :logger => "console"}
|
31
|
+
end
|
32
|
+
|
19
33
|
it "should use hash data as source if supplied" do
|
20
34
|
config = Config.load({"rspec" => "test"})
|
21
35
|
config["rspec"].should == "test"
|
data/spec/unit/hiera_spec.rb
CHANGED
metadata
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
+
- 3
|
8
9
|
- 0
|
9
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
-
|
13
|
+
- Puppet Labs
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
-
default_executable: hiera
|
18
|
+
date: 2012-01-12 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: A pluggable data store for hierarcical data
|
22
|
-
email:
|
22
|
+
email: info@puppetlabs.com
|
23
23
|
executables:
|
24
24
|
- hiera
|
25
25
|
extensions: []
|
@@ -28,14 +28,20 @@ extra_rdoc_files: []
|
|
28
28
|
|
29
29
|
files:
|
30
30
|
- bin/hiera
|
31
|
-
- lib/hiera.rb
|
32
|
-
- lib/hiera/puppet_logger.rb
|
31
|
+
- lib/hiera/backend/yaml_backend.rb
|
33
32
|
- lib/hiera/backend.rb
|
34
33
|
- lib/hiera/config.rb
|
35
34
|
- lib/hiera/console_logger.rb
|
36
|
-
- lib/hiera/
|
37
|
-
|
38
|
-
|
35
|
+
- lib/hiera/puppet_logger.rb
|
36
|
+
- lib/hiera.rb
|
37
|
+
- spec/spec.opts
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- spec/unit/backend/yaml_backend_spec.rb
|
40
|
+
- spec/unit/backend_spec.rb
|
41
|
+
- spec/unit/config_spec.rb
|
42
|
+
- spec/unit/console_logger_spec.rb
|
43
|
+
- spec/unit/hiera_spec.rb
|
44
|
+
homepage: https://github.com/puppetlabs/hiera/
|
39
45
|
licenses: []
|
40
46
|
|
41
47
|
post_install_message:
|
@@ -44,31 +50,35 @@ rdoc_options: []
|
|
44
50
|
require_paths:
|
45
51
|
- lib
|
46
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
47
54
|
requirements:
|
48
55
|
- - ">="
|
49
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
50
58
|
segments:
|
51
59
|
- 0
|
52
60
|
version: "0"
|
53
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
54
63
|
requirements:
|
55
64
|
- - ">="
|
56
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
57
67
|
segments:
|
58
68
|
- 0
|
59
69
|
version: "0"
|
60
70
|
requirements: []
|
61
71
|
|
62
72
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.8.10
|
64
74
|
signing_key:
|
65
75
|
specification_version: 3
|
66
76
|
summary: Light weight hierarcical data store
|
67
77
|
test_files:
|
68
78
|
- spec/spec.opts
|
69
79
|
- spec/spec_helper.rb
|
80
|
+
- spec/unit/backend/yaml_backend_spec.rb
|
70
81
|
- spec/unit/backend_spec.rb
|
82
|
+
- spec/unit/config_spec.rb
|
71
83
|
- spec/unit/console_logger_spec.rb
|
72
84
|
- spec/unit/hiera_spec.rb
|
73
|
-
- spec/unit/config_spec.rb
|
74
|
-
- spec/unit/backend/yaml_backend_spec.rb
|