Permalink
Browse files

Fix logic around handling of defaults in array searches. It used to

always return [nil] for unknown data in array searches now it returns
the supplied default.
  • Loading branch information...
1 parent 51a0a57 commit aa6af39d03175c3a400973819a122ddd8929e3bf @ripienaar committed Jun 21, 2011
Showing with 20 additions and 2 deletions.
  1. +1 −0 CHANGES.txt
  2. +5 −2 lib/hiera/backend.rb
  3. +14 −0 spec/unit/backend_spec.rb
View
@@ -1,3 +1,4 @@
+2011/06/21 - Fix an issue handling defaults in array searches
2011/06/12 - Release 0.2.0
2011/06/11 - Add a Puppet logger plugin
2011/06/11 - Parse variables in String, Hash and Array data
@@ -125,7 +125,7 @@ def parse_answer(data, scope, extra_data={})
def resolve_answer(answer, resolution_type)
case resolution_type
when :array
- [answer].flatten.uniq.sort
+ [answer].flatten.uniq.compact.sort
else
answer
end
@@ -157,7 +157,10 @@ def lookup(key, default, scope, order_override, resolution_type)
end
end
- resolve_answer(answer, resolution_type) || parse_string(default, scope)
+ answer = resolve_answer(answer, resolution_type) || parse_string(default, scope)
+
+ return default if answer == empty_answer(resolution_type)
+ return answer
end
end
end
@@ -220,6 +220,20 @@ class Hiera
Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == "test_test"
end
+
+ it "should correctly handle string default data" do
+ Config.load({:yaml => {:datadir => "/tmp"}})
+ Config.load_backends
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil)
+ Backend.lookup("key", "test", {}, nil, nil).should == "test"
+ end
+
+ it "should correctly handle array default data" do
+ Config.load({:yaml => {:datadir => "/tmp"}})
+ Config.load_backends
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :array)
+ Backend.lookup("key", ["test"], {}, nil, :array).should == ["test"]
+ end
end
end
end

0 comments on commit aa6af39

Please sign in to comment.