|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | shared_examples 'agent examples' do |
4 | | - it { should contain_class('puppet::package') } |
5 | 4 | it { should contain_class('puppet::agent') } |
6 | 5 | it { should compile.with_all_deps } |
7 | 6 | it { should contain_ini_setting('report_server').with_value('puppet_reports.example.com') } |
|
10 | 9 | it { should contain_package('puppet') } |
11 | 10 | end |
12 | 11 |
|
13 | | -describe 'puppet::agent' do |
14 | | - describe "sample agent configuration from documentation" do |
15 | | - let(:params) {{ |
16 | | - :server => 'puppet.example.com', |
17 | | - :report_server => 'puppet_reports.example.com', |
18 | | - :method => 'service', |
19 | | - }} |
20 | | - context 'CentOS, RedHat, Debian, Ubuntu' do |
21 | | - ['RedHat', 'CentOS', 'Debian', 'Ubuntu'].each do |operatingsystem| |
| 12 | +PuppetSpecFacts.facts_for_platform_by_name(["Debian_wheezy_7.7_amd64_3.7.2_structured", "CentOS_5.11_x86_64_3.7.1_structured", "FreeBSD_10.0-RELEASE_amd64_3.6.2_structured"]).each do |name, facthash| |
| 13 | +describe "puppet::agent" do |
| 14 | + let(:facts) { facthash } |
22 | 15 |
|
23 | | - osfamily = 'Redhat' if ['RedHat', 'CentOS'].include? operatingsystem |
24 | | - osfamily ||= 'Debian' |
| 16 | + context "running on #{name}" do |
| 17 | + [true, false].each do |manage_repos| |
25 | 18 |
|
26 | | - let(:facts) {{ |
27 | | - :osfamily => osfamily, |
28 | | - :operatingsystem => operatingsystem, |
29 | | - :lsbdistid => operatingsystem, |
30 | | - :lsbdistcodename => 'lolwut' |
31 | | - }} |
32 | | - context 'running as service' do |
| 19 | + context "when manage_repos => #{manage_repos}" do |
33 | 20 | let(:params) {{ |
34 | 21 | :server => 'puppet.example.com', |
35 | 22 | :report_server => 'puppet_reports.example.com', |
36 | | - :method => 'service', |
| 23 | + :manage_repos => manage_repos, |
37 | 24 | }} |
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 |
45 | | - 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/) |
| 25 | + |
| 26 | + case facthash['osfamily'] |
| 27 | + when 'RedHat' |
| 28 | + it_behaves_like "agent examples" |
| 29 | + it { |
| 30 | + is_expected.to contain_class('Puppet::Package::Repository') if manage_repos == true |
| 31 | + is_expected.to contain_yumrepo('puppetlabs-products') if manage_repos == true |
| 32 | + is_expected.to_not contain_yumrepo('puppetlabs-products') if manage_repos == false |
| 33 | + is_expected.to_not contain_apt__source('puppetlabs') |
| 34 | + } |
| 35 | + when 'Debian' |
| 36 | + it_behaves_like "agent examples" |
| 37 | + it { is_expected.to contain_class('Puppet::Package::Repository') if manage_repos == true } |
| 38 | + it { should_not contain_class('puppetlabs_yum') } |
| 39 | + if manage_repos == true |
| 40 | + it { |
| 41 | + is_expected.to contain_class('puppetlabs_apt') |
| 42 | + is_expected.to contain_apt__source('puppetlabs') |
| 43 | + } |
| 44 | + elsif manage_repos == false |
| 45 | + it { is_expected.to_not contain_class('puppetlabs_apt') } |
| 46 | + end |
| 47 | + when 'FreeBSD' |
| 48 | + if manage_repos == false |
| 49 | + it { |
| 50 | + is_expected.to_not contain_class('puppetlabs_apt') |
| 51 | + is_expected.to_not contain_class('puppetlabs_yum') |
| 52 | + is_expected.to compile.with_all_deps |
| 53 | + } |
| 54 | + end |
86 | 55 | end |
87 | 56 | 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') |
| 57 | + end |
| 58 | + ['service','cron','only_service'].each do |agent_method| |
| 59 | + manage_repos = false if facthash['osfamily'] == 'FreeBSD' |
| 60 | + context "method => #{agent_method}" do |
| 61 | + describe "agent configuration on #{facthash["osfamily"]}" do |
| 62 | + let(:params) {{ |
| 63 | + :server => 'puppet.example.com', |
| 64 | + :report_server => 'puppet_reports.example.com', |
| 65 | + :method => agent_method, |
| 66 | + :manage_repos => manage_repos, |
| 67 | + }} |
| 68 | + |
| 69 | + it_behaves_like "agent examples" |
| 70 | + case agent_method |
| 71 | + when 'service' |
| 72 | + it { should contain_service('puppet_agent').with({ :ensure => "running" }) } |
| 73 | + it { should contain_cron('puppet agent') } |
| 74 | + when 'cron' |
| 75 | + it { should contain_service('puppet_agent').with({ :ensure => "stopped" }) } |
| 76 | + it { should contain_cron('puppet agent') } |
| 77 | + when 'only_service' |
| 78 | + it { should contain_service('puppet_agent').with({ :ensure => "running" }) } |
| 79 | + it { should_not contain_cron('puppet agent') } |
| 80 | + end |
100 | 81 | end |
101 | 82 | end |
102 | | - |
103 | 83 | end |
104 | 84 | end |
105 | 85 | end |
106 | 86 | end |
| 87 | + |
0 commit comments