]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Handle undef for parameter argument
authorDan Bode <dan@puppetlabs.com>
Tue, 14 Aug 2012 01:52:00 +0000 (18:52 -0700)
committerJeff McCune <jeff@puppetlabs.com>
Thu, 25 Oct 2012 17:54:33 +0000 (10:54 -0700)
This commit adds better handling of the case where
undef is passed as the parameter value.

This works by converting '' into []

lib/puppet/parser/functions/defined_with_params.rb
spec/functions/defined_with_params_spec.rb
spec/functions/ensure_resource_spec.rb

index e09e41cd546002d3f05d513eaf14a627706dde28..d7df306c7932e6f310669c58c4c21a1a0a291b85 100644 (file)
@@ -20,7 +20,9 @@ ENDOFDOC
 ) do |vals|
   reference, params = vals
   raise(ArgumentError, 'Must specify a reference') unless reference
-  params ||= {}
+  if (! params) || params == ''
+    params = {}
+  end
   ret = false
   if resource = findresource(reference.to_s)
     matches = params.collect do |key, value|
index 21c08a0484f50c43c973a4022c4e5e2c726408f1..f995b6793ede46d1986ace61c31fca5d7c1e5d19 100644 (file)
@@ -26,6 +26,7 @@ describe 'defined_with_params' do
       should run.with_params('User[dan]', {'ensure' => 'present'}).and_return(true)
       should run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true)
       should run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false)
+      should run.with_params('User[dan]', '').and_return(true)
     end
   end
 end
index e45a6d0c7ab80122d97836ecf59354eddbf573ff..e03efdabe373192726d13a602ebffd852c625eaa 100644 (file)
@@ -26,6 +26,7 @@ describe 'ensure_resource' do
     it do
       # these first three should not fail
       should run.with_params('User', 'dan', {})
+      should run.with_params('User', 'dan', '')
       should run.with_params('User', 'dan', {'ensure' => 'present'})
       should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false})
       #  test that this fails