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
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/defined_with_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ret = false
if resource = findresource(reference.to_s)
matches = params.collect do |key, value|
resource[key] == value
resource[key] == (value.eql?(:undef) ? nil : value) # eql? avoids bugs caused by monkeypatching in puppet
end
ret = params.empty? || !matches.include?(false)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/functions/defined_with_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@
it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true) }
it { is_expected.to run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false) }
end

describe 'when passing undef values' do
let :pre_condition do
'file { "/tmp/a": }'
end

it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) }
it { is_expected.to run.with_params('File[/tmp/a]', { 'owner' => :undef }).and_return(true) }
end
end
7 changes: 7 additions & 0 deletions spec/functions/ensure_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
it { expect(lambda { catalogue }).to contain_user('username2').without_ensure }
end

describe 'after running ensure_resource("user", "username1", { "gid" => undef })' do
before { subject.call(['User', 'username1', { "gid" => :undef }]) }

# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
end

describe 'after running ensure_resource("user", ["username1", "username2"], {})' do
before { subject.call(['User', ['username1', 'username2'], {}]) }

Expand Down