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 @@ -29,7 +29,7 @@
# 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)
type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name)
elsif reference.is_a?(Puppet::Resource)
type = reference.resource_type
title = reference.title
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/test/manifests/deftype.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define test::deftype($param = 'foo') {
notify { "deftype: $title": }
}
10 changes: 10 additions & 0 deletions spec/functions/defined_with_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@
end
end
end

describe 'when passed a defined type' do
let :pre_condition do
'test::deftype { "foo": }'
end
it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) }
it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) }
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
end
18 changes: 18 additions & 0 deletions spec/functions/ensure_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
it { expect(lambda { catalogue }).to contain_user('username1').without_gid }
end

describe 'after running ensure_resource("test::deftype", "foo", {})' do
before { subject.call(['test::deftype', 'foo', {}]) }

# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
end
end

context 'given a catalog with UTF8 chars' do
Expand Down Expand Up @@ -114,4 +121,15 @@
}
end
end

context 'given a catalog with "test::deftype { foo: }"' do
let(:pre_condition) { 'test::deftype { "foo": }' }

describe 'after running ensure_resource("test::deftype", "foo", {})' do
before { subject.call(['test::deftype', 'foo', {}]) }

# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
end
end
end