Please review pull request #18: (#12037) hiera-puppet should support hash values. opened by (nanliu)
Description:
Puppet support hashes, so hiera-puppet backend should also support hash
values.
- Opened: Sat Jan 21 21:15:08 UTC 2012
- Based on: puppetlabs:master (06e70f3768a7cfd0ceaa9135d7e0054f3f0a34fa)
- Requested merge: nanliu:ticket/12037 (eb800e40ee11145aa77191c3c67b38f6515f6682)
Diff follows:
diff --git a/lib/hiera/backend/puppet_backend.rb b/lib/hiera/backend/puppet_backend.rb
index cb7a8ea..a39699d 100644
--- a/lib/hiera/backend/puppet_backend.rb
+++ b/lib/hiera/backend/puppet_backend.rb
@@ -74,6 +74,8 @@ def lookup(key, scope, order_override, resolution_type)
case resolution_type
when :array
answer << Backend.parse_answer(temp_answer, scope)
+ when :hash
+ answer = Backend.parse_answer(temp_answer, scope).merge answer
else
answer = Backend.parse_answer(temp_answer, scope)
break
diff --git a/spec/unit/puppet_backend_spec.rb b/spec/unit/puppet_backend_spec.rb
index 61f94cf..4e50906 100644
--- a/spec/unit/puppet_backend_spec.rb
+++ b/spec/unit/puppet_backend_spec.rb
@@ -110,6 +110,37 @@ module Backend
@backend.expects(:hierarchy).with(@scope, nil).returns(["rspec", "test"])
@backend.lookup("key", @scope, nil, :array).should == ["rspec::key", "test::key"]
end
+
+
+ it "should return a hash of found data for hash searches" do
+ Backend.expects(:empty_answer).returns({})
+ Backend.expects(:parse_answer).with("rspec::key", @scope).returns({'rspec'=>'key'})
+ Backend.expects(:parse_answer).with("test::key", @scope).returns({'test'=>'key'})
+ catalog = mock
+ catalog.expects(:classes).returns(["rspec", "test"])
+ @mockscope.expects(:catalog).returns(catalog)
+ @mockscope.expects(:function_include).never
+ @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec::key")
+ @mockscope.expects(:lookupvar).with("test::key").returns("test::key")
+
+ @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec", "test"])
+ @backend.lookup("key", @scope, nil, :hash).should == {'rspec'=>'key', 'test'=>'key'}
+ end
+
+ it "should return a merged hash of found data for hash searches" do
+ Backend.expects(:empty_answer).returns({})
+ Backend.expects(:parse_answer).with("rspec::key", @scope).returns({'rspec'=>'key', 'common'=>'rspec'})
+ Backend.expects(:parse_answer).with("test::key", @scope).returns({'test'=>'key', 'common'=>'rspec'})
+ catalog = mock
+ catalog.expects(:classes).returns(["rspec", "test"])
+ @mockscope.expects(:catalog).returns(catalog)
+ @mockscope.expects(:function_include).never
+ @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec::key")
+ @mockscope.expects(:lookupvar).with("test::key").returns("test::key")
+
+ @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec", "test"])
+ @backend.lookup("key", @scope, nil, :hash).should == {'rspec'=>'key', 'common'=>'rspec', 'test'=>'key'}
+ end
end
end
end
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
