From 9244c67206363f8e887531b164fc24cef729f3d8 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Thu, 27 Apr 2017 10:00:04 +0100 Subject: 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. --- spec/fixtures/test/manifests/deftype.pp | 3 +++ spec/functions/defined_with_params_spec.rb | 8 ++++++++ spec/functions/ensure_resource_spec.rb | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 spec/fixtures/test/manifests/deftype.pp (limited to 'spec') diff --git a/spec/fixtures/test/manifests/deftype.pp b/spec/fixtures/test/manifests/deftype.pp new file mode 100644 index 0000000..825f8fe --- /dev/null +++ b/spec/fixtures/test/manifests/deftype.pp @@ -0,0 +1,3 @@ +define test::deftype($param = 'foo') { + notify { "deftype: $title": } +} diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 7118d85..775fa74 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -55,4 +55,12 @@ describe 'defined_with_params' do 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) } + end end diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index 5366205..c847bf7 100755 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -38,6 +38,13 @@ describe 'ensure_resource' do 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 @@ -114,4 +121,15 @@ describe 'ensure_resource' do } 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 -- cgit v1.2.3