| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- require 'spec_helper'
- describe 'ensure_resource' do
- it { is_expected.not_to eq(nil) }
- it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Must specify a type}) }
- it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, %r{Must specify a title}) }
- if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
- it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) }
- else
- it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
- end
- it {
- pending('should not accept numbers as arguments')
- is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError)
- }
- context 'when given an empty catalog' do
- describe 'after running ensure_resource("user", "username1", {})' do
- before(:each) { subject.call(['User', 'username1', {}]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').without_ensure }
- end
- describe 'after running ensure_resource("user", "username1", { gid => undef })' do
- before(:each) { subject.call(['User', 'username1', { 'gid' => :undef }]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').without_ensure }
- it { expect(-> { catalogue }).to contain_user('username1').without_gid }
- end
- describe 'after running ensure_resource("user", "username1", { ensure => present, gid => undef })' do
- before(:each) { subject.call(['User', 'username1', { 'ensure' => 'present', 'gid' => :undef }]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
- it { expect(-> { catalogue }).to contain_user('username1').without_gid }
- end
- describe 'after running ensure_resource("test::deftype", "foo", {})' do
- before(:each) { subject.call(['test::deftype', 'foo', {}]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure }
- end
- end
- context 'when given a catalog with UTF8 chars' do
- describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", {})' do
- before(:each) { subject.call(['User', 'Şắოрŀễ Ţëם', {}]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
- end
- describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { gid => undef })' do
- before(:each) { subject.call(['User', 'Şắოрŀễ Ţëם', { 'gid' => :undef }]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
- it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
- end
- describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { ensure => present, gid => undef })' do
- before(:each) { subject.call(['User', 'Şắოрŀễ Ţëם', { 'ensure' => 'present', 'gid' => :undef }]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') }
- it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
- end
- end
- context 'when given a catalog with "user { username1: ensure => present }"' do
- let(:pre_condition) { 'user { username1: ensure => present }' }
- describe 'after running ensure_resource("user", "username1", {})' do
- before(:each) { subject.call(['User', 'username1', {}]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
- end
- describe 'after running ensure_resource("user", "username2", {})' do
- before(:each) { subject.call(['User', 'username2', {}]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
- it { expect(-> { catalogue }).to contain_user('username2').without_ensure }
- end
- describe 'after running ensure_resource("user", "username1", { gid => undef })' do
- before(:each) { subject.call(['User', 'username1', { 'gid' => :undef }]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
- end
- describe 'after running ensure_resource("user", ["username1", "username2"], {})' do
- before(:each) { subject.call(['User', %w[username1 username2], {}]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
- it { expect(-> { catalogue }).to contain_user('username2').without_ensure }
- end
- describe 'when providing already set params' do
- let(:params) { { 'ensure' => 'present' } }
- before(:each) { subject.call(['User', %w[username2 username3], params]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_user('username1').with(params) }
- it { expect(-> { catalogue }).to contain_user('username2').with(params) }
- end
- context 'when trying to add params' do
- it {
- is_expected.to run \
- .with_params('User', 'username1', 'ensure' => 'present', 'shell' => true) \
- .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, %r{User\[username1\] is already declared})
- }
- end
- end
- context 'when given a catalog with "test::deftype { foo: }"' do
- let(:pre_condition) { 'test::deftype { "foo": }' }
- describe 'after running ensure_resource("test::deftype", "foo", {})' do
- before(:each) { subject.call(['test::deftype', 'foo', {}]) }
- # this lambda is required due to strangeness within rspec-puppet's expectation handling
- it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure }
- end
- end
- end
|