1 | require 'spec_helper'
|
---|
2 |
|
---|
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.version.to_f >= 4.6
|
---|
8 | it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) }
|
---|
9 | else
|
---|
10 | it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
|
---|
11 | end
|
---|
12 |
|
---|
13 | it {
|
---|
14 | pending("should not accept numbers as arguments")
|
---|
15 | is_expected.to run.with_params(1,2,3).and_raise_error(Puppet::ParseError)
|
---|
16 | }
|
---|
17 |
|
---|
18 | context 'given an empty catalog' do
|
---|
19 | describe 'after running ensure_resource("user", "username1", {})' do
|
---|
20 | before { subject.call(['User', 'username1', {}]) }
|
---|
21 |
|
---|
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 }
|
---|
24 | end
|
---|
25 |
|
---|
26 | describe 'after running ensure_resource("user", "username1", { gid => undef })' do
|
---|
27 | before { subject.call(['User', 'username1', { 'gid' => :undef }]) }
|
---|
28 |
|
---|
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 }
|
---|
32 | end
|
---|
33 |
|
---|
34 | describe 'after running ensure_resource("user", "username1", { ensure => present, gid => undef })' do
|
---|
35 | before { subject.call(['User', 'username1', { 'ensure' => 'present', 'gid' => :undef }]) }
|
---|
36 |
|
---|
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 }
|
---|
40 | end
|
---|
41 |
|
---|
42 | end
|
---|
43 |
|
---|
44 | context 'given a catalog with "user { username1: ensure => present }"' do
|
---|
45 | let(:pre_condition) { 'user { username1: ensure => present }' }
|
---|
46 |
|
---|
47 | describe 'after running ensure_resource("user", "username1", {})' do
|
---|
48 | before { subject.call(['User', 'username1', {}]) }
|
---|
49 |
|
---|
50 | # this lambda is required due to strangeness within rspec-puppet's expectation handling
|
---|
51 | it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
|
---|
52 | end
|
---|
53 |
|
---|
54 | describe 'after running ensure_resource("user", "username2", {})' do
|
---|
55 | before { subject.call(['User', 'username2', {}]) }
|
---|
56 |
|
---|
57 | # this lambda is required due to strangeness within rspec-puppet's expectation handling
|
---|
58 | it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
|
---|
59 | it { expect(lambda { catalogue }).to contain_user('username2').without_ensure }
|
---|
60 | end
|
---|
61 |
|
---|
62 | describe 'after running ensure_resource("user", "username1", { gid => undef })' do
|
---|
63 | before { subject.call(['User', 'username1', { 'gid' => :undef }]) }
|
---|
64 |
|
---|
65 | # this lambda is required due to strangeness within rspec-puppet's expectation handling
|
---|
66 | it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
|
---|
67 | end
|
---|
68 |
|
---|
69 | describe 'after running ensure_resource("user", ["username1", "username2"], {})' do
|
---|
70 | before { subject.call(['User', ['username1', 'username2'], {}]) }
|
---|
71 |
|
---|
72 | # this lambda is required due to strangeness within rspec-puppet's expectation handling
|
---|
73 | it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') }
|
---|
74 | it { expect(lambda { catalogue }).to contain_user('username2').without_ensure }
|
---|
75 | end
|
---|
76 |
|
---|
77 | describe 'when providing already set params' do
|
---|
78 | let(:params) { { 'ensure' => 'present' } }
|
---|
79 | before { subject.call(['User', ['username2', 'username3'], params]) }
|
---|
80 |
|
---|
81 | # this lambda is required due to strangeness within rspec-puppet's expectation handling
|
---|
82 | it { expect(lambda { catalogue }).to contain_user('username1').with(params) }
|
---|
83 | it { expect(lambda { catalogue }).to contain_user('username2').with(params) }
|
---|
84 | end
|
---|
85 |
|
---|
86 | context 'when trying to add params' do
|
---|
87 | it { is_expected.to run \
|
---|
88 | .with_params('User', 'username1', { 'ensure' => 'present', 'shell' => true }) \
|
---|
89 | .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, /User\[username1\] is already declared/)
|
---|
90 | }
|
---|
91 | end
|
---|
92 | end
|
---|
93 | end
|
---|