diff options
-rw-r--r-- | lib/puppet/parser/functions/defined_with_params.rb | 20 | ||||
-rwxr-xr-x | spec/functions/defined_with_params_spec.rb | 18 |
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index 99687ae..f2c6230 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -24,7 +24,25 @@ ENDOFDOC params = {} end ret = false - if resource = findresource(reference.to_s) + + if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + # Workaround for PE-20308 + if reference.is_a?(String) + type_name, title = Puppet::Resource.type_and_title(reference, nil) + type = Puppet::Type.type(type_name) + elsif reference.is_a?(Puppet::Resource) + type = reference.resource_type + title = reference.title + else + raise(ArgumentError, "Reference is not understood: '#{reference.class}'") + end + #end workaround + else + type = reference.to_s + title = nil + end + + if resource = findresource(type, title) matches = params.collect do |key, value| # eql? avoids bugs caused by monkeypatching in puppet resource_is_undef = resource[key].eql?(:undef) || resource[key].nil? diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index a0db0b7..979e25a 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -37,4 +37,22 @@ describe 'defined_with_params' do it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) } it { is_expected.to run.with_params('File[/tmp/a]', { 'ensure' => 'present', 'owner' => :undef }).and_return(true) } end + + describe 'when the reference is a' do + let :pre_condition do + 'user { "dan": }' + end + context 'reference' do + it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) } + end + if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + context 'array' do + it 'fails' do + expect { + subject.call([['User[dan]'], {}]) + }.to raise_error ArgumentError, /not understood: 'Array'/ + end + end + end + end end |