Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit 5b6b898

Browse files
author
Daniel Dreier
committed
Add rspec tests for puppet::agent
1 parent 67532f8 commit 5b6b898

File tree

3 files changed

+87
-14
lines changed

3 files changed

+87
-14
lines changed

spec/classes/agent_spec.rb

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
require 'spec_helper'
22

3+
shared_examples 'agent examples' do
4+
it { should contain_class('puppet::package') }
5+
it { should contain_class('puppet::agent') }
6+
it { should compile.with_all_deps }
7+
it { should contain_ini_setting('report_server').with_value('puppet_reports.example.com') }
8+
it { should contain_ini_setting('server').with_value('puppet.example.com') }
9+
it { should contain_ini_setting('pluginsync').with_value(true) }
10+
it { should contain_package('puppet') }
11+
end
12+
313
describe 'puppet::agent' do
414
describe "sample agent configuration from documentation" do
515
let(:params) {{
@@ -19,21 +29,77 @@
1929
:lsbdistid => operatingsystem,
2030
:lsbdistcodename => 'lolwut'
2131
}}
22-
23-
it { should contain_class('puppet::package') }
24-
it { should contain_class('puppet::agent') }
25-
26-
it { should compile.with_all_deps }
27-
it { should contain_ini_setting('report_server').with_value('puppet_reports.example.com') }
28-
it { should contain_ini_setting('server').with_value('puppet.example.com') }
29-
it { should contain_ini_setting('pluginsync').with_value(true) }
30-
31-
it { should contain_package('puppet') }
32-
it do
33-
should contain_service('puppet_agent').with({
34-
:ensure => "running"
35-
})
32+
context 'running as service' do
33+
let(:params) {{
34+
:server => 'puppet.example.com',
35+
:report_server => 'puppet_reports.example.com',
36+
:method => 'service',
37+
}}
38+
it_behaves_like "agent examples"
39+
it do
40+
should contain_service('puppet_agent').with({
41+
:ensure => "running"
42+
})
43+
should contain_cron('puppet agent')
44+
end
3645
end
46+
context 'method => "only_service"' do
47+
let(:params) {{
48+
:server => 'puppet.example.com',
49+
:report_server => 'puppet_reports.example.com',
50+
:method => 'only_service',
51+
}}
52+
it_behaves_like "agent examples"
53+
it do
54+
should contain_service('puppet_agent').with({
55+
:ensure => "running"
56+
})
57+
should_not contain_cron('puppet agent')
58+
end
59+
end
60+
context 'method => "none"' do
61+
let(:params) {{
62+
:server => 'puppet.example.com',
63+
:report_server => 'puppet_reports.example.com',
64+
:method => 'only_service',
65+
}}
66+
it_behaves_like "agent examples"
67+
it do
68+
should contain_service('puppet_agent').with({
69+
:ensure => "running"
70+
})
71+
should_not contain_cron('puppet agent')
72+
end
73+
end
74+
context 'method => "cron"' do
75+
let(:params) {{
76+
:server => 'puppet.example.com',
77+
:report_server => 'puppet_reports.example.com',
78+
:method => 'cron',
79+
}}
80+
it_behaves_like "agent examples"
81+
it do
82+
should_not contain_service('puppet_agent').with({
83+
:ensure => "running"
84+
})
85+
should contain_cron('puppet agent').with_command(/puppet agent/)
86+
end
87+
end
88+
context 'manage_repos => false' do
89+
let(:params) {{
90+
:server => 'puppet.example.com',
91+
:report_server => 'puppet_reports.example.com',
92+
:manage_repos => false,
93+
}}
94+
it_behaves_like "agent examples"
95+
it do
96+
should contain_service('puppet_agent')
97+
should contain_cron('puppet agent').with_command(/puppet agent/)
98+
should_not contain_yumrepo('puppetlabs-products')
99+
should_not contain_apt__source('puppetlabs')
100+
end
101+
end
102+
37103
end
38104
end
39105
end

tests/agent_cron.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class { 'puppet::agent':
2+
method => 'cron',
3+
}

tests/agent_noapt.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class { 'puppet::agent':
2+
method => 'cron',
3+
manage_repos => false,
4+
}

0 commit comments

Comments
 (0)