3 describe 'ensure_resource' do
4 it { is_expected.not_to eq(nil) }
5 it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Must specify a type}) }
6 it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, %r{Must specify a title}) }
7 if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
8 it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) }
10 it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
14 pending('should not accept numbers as arguments')
15 is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError)
18 context 'when given an empty catalog' do
19 describe 'after running ensure_resource("user", "username1", {})' do
20 before(:each) { subject.execute('User', 'username1', {}) }
22 # this lambda is required due to strangeness within rspec-puppet's expectation handling
23 it { expect(-> { catalogue }).to contain_user('username1').without_ensure }
26 describe 'after running ensure_resource("user", "username1", { gid => undef })' do
27 before(:each) { subject.execute('User', 'username1', 'gid' => undef_value) }
29 # this lambda is required due to strangeness within rspec-puppet's expectation handling
30 it { expect(-> { catalogue }).to contain_user('username1').without_ensure }
31 it { expect(-> { catalogue }).to contain_user('username1').without_gid }
34 describe 'after running ensure_resource("user", "username1", { ensure => present, gid => undef })' do
35 before(:each) { subject.execute('User', 'username1', 'ensure' => 'present', 'gid' => undef_value) }
37 # this lambda is required due to strangeness within rspec-puppet's expectation handling
38 it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
39 it { expect(-> { catalogue }).to contain_user('username1').without_gid }
42 describe 'after running ensure_resource("test::deftype", "foo", {})' do
43 let(:pre_condition) { 'define test::deftype { }' }
45 before(:each) { subject.execute('test::deftype', 'foo', {}) }
47 # this lambda is required due to strangeness within rspec-puppet's expectation handling
48 it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure }
52 context 'when given a catalog with UTF8 chars' do
53 describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", {})' do
54 before(:each) { subject.execute('User', 'Şắოрŀễ Ţëם', {}) }
56 # this lambda is required due to strangeness within rspec-puppet's expectation handling
57 it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
60 describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { gid => undef })' do
61 before(:each) { subject.execute('User', 'Şắოрŀễ Ţëם', 'gid' => undef_value) }
63 # this lambda is required due to strangeness within rspec-puppet's expectation handling
64 it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
65 it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
68 describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { ensure => present, gid => undef })' do
69 before(:each) { subject.execute('User', 'Şắოрŀễ Ţëם', 'ensure' => 'present', 'gid' => undef_value) }
71 # this lambda is required due to strangeness within rspec-puppet's expectation handling
72 it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') }
73 it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
77 context 'when given a catalog with "user { username1: ensure => present }"' do
78 let(:pre_condition) { 'user { username1: ensure => present }' }
80 describe 'after running ensure_resource("user", "username1", {})' do
81 before(:each) { subject.execute('User', 'username1', {}) }
83 # this lambda is required due to strangeness within rspec-puppet's expectation handling
84 it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
87 describe 'after running ensure_resource("user", "username2", {})' do
88 before(:each) { subject.execute('User', 'username2', {}) }
90 # this lambda is required due to strangeness within rspec-puppet's expectation handling
91 it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
92 it { expect(-> { catalogue }).to contain_user('username2').without_ensure }
95 describe 'after running ensure_resource("user", "username1", { gid => undef })' do
96 before(:each) { subject.execute('User', 'username1', 'gid' => undef_value) }
98 # this lambda is required due to strangeness within rspec-puppet's expectation handling
99 it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
102 describe 'after running ensure_resource("user", ["username1", "username2"], {})' do
103 before(:each) { subject.execute('User', ['username1', 'username2'], {}) }
105 # this lambda is required due to strangeness within rspec-puppet's expectation handling
106 it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
107 it { expect(-> { catalogue }).to contain_user('username2').without_ensure }
110 describe 'when providing already set params' do
111 let(:params) { { 'ensure' => 'present' } }
113 before(:each) { subject.execute('User', ['username2', 'username3'], params) }
115 # this lambda is required due to strangeness within rspec-puppet's expectation handling
116 it { expect(-> { catalogue }).to contain_user('username1').with(params) }
117 it { expect(-> { catalogue }).to contain_user('username2').with(params) }
120 context 'when trying to add params' do
123 .with_params('User', 'username1', 'ensure' => 'present', 'shell' => true) \
124 .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, %r{User\[username1\] is already declared})
129 context 'when given a catalog with "test::deftype { foo: }"' do
130 let(:pre_condition) { 'define test::deftype { } test::deftype { "foo": }' }
132 describe 'after running ensure_resource("test::deftype", "foo", {})' do
133 before(:each) { subject.execute('test::deftype', 'foo', {}) }
135 # this lambda is required due to strangeness within rspec-puppet's expectation handling
136 it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure }
140 if Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0