Skip to content

Commit 9244c67

Browse files
domclealHelen Campbell
authored andcommitted
Test for defined_with_params() returning false for defined types
defined_with_params() now returns false for defined types, causing duplicate resources when using ensure_resources(). Introduced by 4f19c27 in PE-20308.
1 parent 052d55b commit 9244c67

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@
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+
end
5866
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)