2012-08-16 00:56:57 +02:00
|
|
|
require 'spec_helper'
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2012-08-16 00:56:57 +02:00
|
|
|
describe 'ensure_resource' do
|
2015-06-01 13:21:59 +02:00
|
|
|
it { is_expected.not_to eq(nil) }
|
|
|
|
it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) }
|
|
|
|
it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) }
|
|
|
|
it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
|
|
|
|
it {
|
|
|
|
pending("should not accept numbers as arguments")
|
|
|
|
is_expected.to run.with_params(1,2,3).and_raise_error(Puppet::ParseError)
|
|
|
|
}
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
context 'given a catalog with "user { username1: ensure => present }"' do
|
|
|
|
let(:pre_condition) { 'user { username1: ensure => present }' }
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'after running ensure_resource("user", "username1", {})' do
|
|
|
|
before { subject.call(['User', 'username1', {}]) }
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
# this lambda is required due to strangeness within rspec-puppet's expectation handling
|
|
|
|
it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
|
2012-08-16 00:56:57 +02:00
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'after running ensure_resource("user", "username2", {})' do
|
|
|
|
before { subject.call(['User', 'username2', {}]) }
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
# this lambda is required due to strangeness within rspec-puppet's expectation handling
|
|
|
|
it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
|
|
|
|
it { expect(lambda { catalogue }).to contain_user('username2').without_ensure }
|
2012-08-16 00:56:57 +02:00
|
|
|
end
|
2013-05-03 21:47:27 +02:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'after running ensure_resource("user", ["username1", "username2"], {})' do
|
|
|
|
before { subject.call(['User', ['username1', 'username2'], {}]) }
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
# this lambda is required due to strangeness within rspec-puppet's expectation handling
|
|
|
|
it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
|
|
|
|
it { expect(lambda { catalogue }).to contain_user('username2').without_ensure }
|
2013-05-03 21:47:27 +02:00
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'when providing already set params' do
|
|
|
|
let(:params) { { 'ensure' => 'present' } }
|
|
|
|
before { subject.call(['User', ['username2', 'username3'], params]) }
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
# this lambda is required due to strangeness within rspec-puppet's expectation handling
|
|
|
|
it { expect(lambda { catalogue }).to contain_user('username1').with(params) }
|
|
|
|
it { expect(lambda { catalogue }).to contain_user('username2').with(params) }
|
2013-05-03 21:47:27 +02:00
|
|
|
end
|
2014-03-05 21:43:58 +01:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
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, /User\[username1\] is already declared/)
|
|
|
|
}
|
2013-05-03 21:47:27 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-16 00:56:57 +02:00
|
|
|
end
|