Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/puppet/parser/functions/defined_with_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@
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?
Expand Down
18 changes: 18 additions & 0 deletions spec/functions/defined_with_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,22 @@
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