Skip to content

Commit a4b8688

Browse files
authored
Merge pull request puppetlabs#765 from hunner/fix_defines
(PE-20308) Fix defined_with_params() for defined type strings & references
2 parents 5edcf6e + b861976 commit a4b8688

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

lib/puppet/parser/functions/defined_with_params.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Workaround for PE-20308
3030
if reference.is_a?(String)
3131
type_name, title = Puppet::Resource.type_and_title(reference, nil)
32-
type = Puppet::Type.type(type_name)
32+
type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name)
3333
elsif reference.is_a?(Puppet::Resource)
3434
type = reference.resource_type
3535
title = reference.title
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define test::deftype($param = 'foo') {
2+
notify { "deftype: $title": }
3+
}

spec/functions/defined_with_params_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@
5555
end
5656
end
5757
end
58+
59+
describe 'when passed a defined type' do
60+
let :pre_condition do
61+
'test::deftype { "foo": }'
62+
end
63+
it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) }
64+
it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) }
65+
it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
66+
it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) }
67+
end
5868
end

spec/functions/ensure_resource_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
3939
it { expect(lambda { catalogue }).to contain_user('username1').without_gid }
4040
end
41+
42+
describe 'after running ensure_resource("test::deftype", "foo", {})' do
43+
before { subject.call(['test::deftype', 'foo', {}]) }
44+
45+
# this lambda is required due to strangeness within rspec-puppet's expectation handling
46+
it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
47+
end
4148
end
4249

4350
context 'given a catalog with UTF8 chars' do
@@ -114,4 +121,15 @@
114121
}
115122
end
116123
end
124+
125+
context 'given a catalog with "test::deftype { foo: }"' do
126+
let(:pre_condition) { 'test::deftype { "foo": }' }
127+
128+
describe 'after running ensure_resource("test::deftype", "foo", {})' do
129+
before { subject.call(['test::deftype', 'foo', {}]) }
130+
131+
# this lambda is required due to strangeness within rspec-puppet's expectation handling
132+
it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
133+
end
134+
end
117135
end

0 commit comments

Comments
 (0)