Skip to content

Commit d22e71b

Browse files
authored
Merge pull request #971 from syseleven/fix/unquoted_classes
(MODULES-8273) - Make unquoted classes useable
2 parents 19cdf29 + 2033843 commit d22e71b

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lib/puppet/parser/functions/defined_with_params.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
type_name, title = Puppet::Resource.type_and_title(reference, nil)
3232
type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name.downcase)
3333
elsif reference.is_a?(Puppet::Resource)
34-
type = reference.resource_type
34+
type = reference.type
3535
title = reference.title
3636
else
3737
raise(ArgumentError, "Reference is not understood: '#{reference.class}'")

spec/acceptance/defined_with_params_spec.rb

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe 'defined_with_params function' do
44
describe 'success' do
5-
pp = <<-DOC
5+
pp1 = <<-DOC
66
user { 'dan':
77
ensure => present,
88
}
@@ -11,10 +11,29 @@
1111
notify { 'User defined with ensure=>present': }
1212
}
1313
DOC
14-
it 'successfullies notify' do
15-
apply_manifest(pp, :catch_failures => true) do |r|
14+
it 'successfullies checks a type' do
15+
apply_manifest(pp1, :catch_failures => true) do |r|
1616
expect(r.stdout).to match(%r{Notice: User defined with ensure=>present})
1717
end
1818
end
19+
20+
pp2 = <<-DOC
21+
class foo (
22+
$bar,
23+
) {}
24+
25+
class { 'foo':
26+
bar => 'baz',
27+
}
28+
29+
if defined_with_params(Class[foo], { 'bar' => 'baz' }) {
30+
notify { 'Class foo defined with bar=>baz': }
31+
}
32+
DOC
33+
it 'successfullies checks a class' do
34+
apply_manifest(pp2, :catch_failures => true) do |r|
35+
expect(r.stdout).to match(%r{Notice: Class foo defined with bar=>baz})
36+
end
37+
end
1938
end
2039
end

spec/functions/defined_with_params_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,17 @@
7171
it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
7272
it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) }
7373
end
74+
75+
describe 'when passed a class' do
76+
let :pre_condition do
77+
'class test () { } class { "test": }'
78+
end
79+
80+
it { is_expected.to run.with_params('Class[test]', {}).and_return(true) }
81+
it { is_expected.to run.with_params('Class["bar"]', {}).and_return(false) }
82+
it { is_expected.to run.with_params('Class[bar]', {}).and_return(false) }
83+
it { is_expected.to run.with_params(Puppet::Resource.new('class', 'test'), {}).and_return(true) }
84+
it { is_expected.to run.with_params(Puppet::Resource.new('Class["bar"]'), {}).and_return(false) }
85+
it { is_expected.to run.with_params(Puppet::Resource.new('Class[bar]'), {}).and_return(false) }
86+
end
7487
end

0 commit comments

Comments
 (0)