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, /Must specify a type/) }
6 it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /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 'given an empty catalog' do
19 describe 'after running ensure_resource("user", "username1", {})' do
20 before { subject.call(['User', 'username1', {}]) }
22 # this lambda is required due to strangeness within rspec-puppet's expectation handling
23 it { expect(lambda { catalogue }).to contain_user('username1').without_ensure }
26 describe 'after running ensure_resource("user", "username1", { gid => undef })' do
27 before { subject.call(['User', 'username1', { 'gid' => :undef }]) }
29 # this lambda is required due to strangeness within rspec-puppet's expectation handling
30 it { expect(lambda { catalogue }).to contain_user('username1').without_ensure }
31 it { expect(lambda { catalogue }).to contain_user('username1').without_gid }
34 describe 'after running ensure_resource("user", "username1", { ensure => present, gid => undef })' do
35 before { subject.call(['User', 'username1', { 'ensure' => 'present', 'gid' => :undef }]) }
37 # this lambda is required due to strangeness within rspec-puppet's expectation handling
38 it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
39 it { expect(lambda { catalogue }).to contain_user('username1').without_gid }
42 describe 'after running ensure_resource("test::deftype", "foo", {})' do
43 before { subject.call(['test::deftype', 'foo', {}]) }
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 }
50 context 'given a catalog with UTF8 chars' do
51 describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", {})' do
52 before { subject.call(['User', 'Şắოрŀễ Ţëם', {}]) }
54 # this lambda is required due to strangeness within rspec-puppet's expectation handling
55 it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
58 describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { gid => undef })' do
59 before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'gid' => :undef }]) }
61 # this lambda is required due to strangeness within rspec-puppet's expectation handling
62 it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
63 it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
66 describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { ensure => present, gid => undef })' do
67 before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'ensure' => 'present', 'gid' => :undef }]) }
69 # this lambda is required due to strangeness within rspec-puppet's expectation handling
70 it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') }
71 it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
75 context 'given a catalog with "user { username1: ensure => present }"' do
76 let(:pre_condition) { 'user { username1: ensure => present }' }
78 describe 'after running ensure_resource("user", "username1", {})' do
79 before { subject.call(['User', 'username1', {}]) }
81 # this lambda is required due to strangeness within rspec-puppet's expectation handling
82 it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
85 describe 'after running ensure_resource("user", "username2", {})' do
86 before { subject.call(['User', 'username2', {}]) }
88 # this lambda is required due to strangeness within rspec-puppet's expectation handling
89 it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
90 it { expect(lambda { catalogue }).to contain_user('username2').without_ensure }
93 describe 'after running ensure_resource("user", "username1", { gid => undef })' do
94 before { subject.call(['User', 'username1', { 'gid' => :undef }]) }
96 # this lambda is required due to strangeness within rspec-puppet's expectation handling
97 it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
100 describe 'after running ensure_resource("user", ["username1", "username2"], {})' do
101 before { subject.call(['User', ['username1', 'username2'], {}]) }
103 # this lambda is required due to strangeness within rspec-puppet's expectation handling
104 it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
105 it { expect(lambda { catalogue }).to contain_user('username2').without_ensure }
108 describe 'when providing already set params' do
109 let(:params) { { 'ensure' => 'present' } }
110 before { subject.call(['User', ['username2', 'username3'], params]) }
112 # this lambda is required due to strangeness within rspec-puppet's expectation handling
113 it { expect(lambda { catalogue }).to contain_user('username1').with(params) }
114 it { expect(lambda { catalogue }).to contain_user('username2').with(params) }
117 context 'when trying to add params' do
118 it { is_expected.to run \
119 .with_params('User', 'username1', { 'ensure' => 'present', 'shell' => true }) \
120 .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, /User\[username1\] is already declared/)
125 context 'given a catalog with "test::deftype { foo: }"' do
126 let(:pre_condition) { 'test::deftype { "foo": }' }
128 describe 'after running ensure_resource("test::deftype", "foo", {})' do
129 before { subject.call(['test::deftype', 'foo', {}]) }
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 }