Skip to content

(MODULES-8273) - Make unquoted classes useable #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2018
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 @@ -31,7 +31,7 @@
type_name, title = Puppet::Resource.type_and_title(reference, nil)
type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name.downcase)
elsif reference.is_a?(Puppet::Resource)
type = reference.resource_type
type = reference.type
title = reference.title
else
raise(ArgumentError, "Reference is not understood: '#{reference.class}'")
Expand Down
25 changes: 22 additions & 3 deletions spec/acceptance/defined_with_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'defined_with_params function' do
describe 'success' do
pp = <<-DOC
pp1 = <<-DOC
user { 'dan':
ensure => present,
}
Expand All @@ -11,10 +11,29 @@
notify { 'User defined with ensure=>present': }
}
DOC
it 'successfullies notify' do
apply_manifest(pp, :catch_failures => true) do |r|
it 'successfullies checks a type' do
apply_manifest(pp1, :catch_failures => true) do |r|
expect(r.stdout).to match(%r{Notice: User defined with ensure=>present})
end
end

pp2 = <<-DOC
class foo (
$bar,
) {}

class { 'foo':
bar => 'baz',
}

if defined_with_params(Class[foo], { 'bar' => 'baz' }) {
notify { 'Class foo defined with bar=>baz': }
}
DOC
it 'successfullies checks a class' do
apply_manifest(pp2, :catch_failures => true) do |r|
expect(r.stdout).to match(%r{Notice: Class foo defined with bar=>baz})
end
end
end
end
13 changes: 13 additions & 0 deletions spec/functions/defined_with_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@
it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) }
end

describe 'when passed a class' do
let :pre_condition do
'class test () { } class { "test": }'
end

it { is_expected.to run.with_params('Class[test]', {}).and_return(true) }
it { is_expected.to run.with_params('Class["bar"]', {}).and_return(false) }
it { is_expected.to run.with_params('Class[bar]', {}).and_return(false) }
it { is_expected.to run.with_params(Puppet::Resource.new('class', 'test'), {}).and_return(true) }
it { is_expected.to run.with_params(Puppet::Resource.new('Class["bar"]'), {}).and_return(false) }
it { is_expected.to run.with_params(Puppet::Resource.new('Class[bar]'), {}).and_return(false) }
end
end