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

Commit f7020b1

Browse files
committed
Merge pull request #130 from danieldreier/more_testing
Improve tests for puppet::agent
2 parents 7867eaa + 1d976d7 commit f7020b1

File tree

4 files changed

+133
-37
lines changed

4 files changed

+133
-37
lines changed

spec/acceptance/agent_spec.rb

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper_acceptance'
22

33
describe 'agent', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4-
context 'with default parameters' do
4+
context 'with default parameters', :agent_method => 'default' do
55
it 'should run with no errors', :agent do
66
pp = <<-EOS
77
class { 'puppet::agent': }
@@ -13,26 +13,49 @@ class { 'puppet::agent': }
1313
end
1414
end
1515

16-
# context 'running as service' do
17-
# it 'should run with no errors' do
18-
# pp = <<-EOS
19-
# class { 'puppet::agent':
20-
# method => 'service',
21-
# }
22-
# EOS
23-
24-
# # Run it twice and test for idempotency
25-
# apply_manifest(pp, :catch_failures => true)
26-
# expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
27-
# end
28-
#
29-
# describe service('puppet') do
30-
# it {
31-
# should be_enabled
32-
# }
33-
# it {
34-
# should be_running
35-
# }
36-
# end
37-
# end
16+
context 'running as cron', :agent_method => 'cron' do
17+
it 'should run with no errors' do
18+
pp = <<-EOS
19+
class { 'puppet::agent':
20+
method => 'cron',
21+
}
22+
EOS
23+
24+
# Run it twice and test for idempotency
25+
apply_manifest(pp, :catch_failures => true)
26+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
27+
end
28+
29+
describe service('puppet') do
30+
it {
31+
should be_disabled
32+
}
33+
it {
34+
should_not be_running
35+
}
36+
end
37+
end
38+
context 'running as service', :agenttype => 'service' do
39+
it 'should run with no errors' do
40+
pp = <<-EOS
41+
class { 'puppet::agent':
42+
method => 'service',
43+
}
44+
EOS
45+
46+
# Run it twice and test for idempotency
47+
apply_manifest(pp, :catch_failures => true)
48+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
49+
end
50+
51+
describe service('puppet') do
52+
it {
53+
should be_enabled
54+
}
55+
it {
56+
should be_running
57+
}
58+
end
59+
end
60+
3861
end

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)