]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/classes/service_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / classes / service_spec.rb
1 require 'spec_helper'
2
3 describe 'apache::service', :type => :class do
4   let :pre_condition do
5     'include apache::params'
6   end
7   context "on a Debian OS" do
8     let :facts do
9       {
10         :osfamily               => 'Debian',
11         :operatingsystemrelease => '6',
12         :concat_basedir         => '/dne',
13         :lsbdistcodename        => 'squeeze',
14         :operatingsystem        => 'Debian',
15         :id                     => 'root',
16         :kernel                 => 'Linux',
17         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
18         :is_pe                  => false,
19       }
20     end
21     it { is_expected.to contain_service("httpd").with(
22       'name'      => 'apache2',
23       'ensure'    => 'running',
24       'enable'    => 'true'
25       )
26     }
27
28     context "with $service_name => 'foo'" do
29       let (:params) {{ :service_name => 'foo' }}
30       it { is_expected.to contain_service("httpd").with(
31         'name'      => 'foo'
32         )
33       }
34     end
35
36     context "with $service_enable => true" do
37       let (:params) {{ :service_enable => true }}
38       it { is_expected.to contain_service("httpd").with(
39         'name'      => 'apache2',
40         'ensure'    => 'running',
41         'enable'    => 'true'
42         )
43       }
44     end
45
46     context "with $service_enable => false" do
47       let (:params) {{ :service_enable => false }}
48       it { is_expected.to contain_service("httpd").with(
49         'name'      => 'apache2',
50         'ensure'    => 'running',
51         'enable'    => 'false'
52         )
53       }
54     end
55
56     context "$service_enable must be a bool" do
57       let (:params) {{ :service_enable => 'not-a-boolean' }}
58
59       it 'should fail' do
60         expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
61       end
62     end
63
64     context "$service_manage must be a bool" do
65       let (:params) {{ :service_manage => 'not-a-boolean' }}
66
67       it 'should fail' do
68         expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
69       end
70     end
71
72     context "with $service_ensure => 'running'" do
73       let (:params) {{ :service_ensure => 'running', }}
74       it { is_expected.to contain_service("httpd").with(
75         'ensure'    => 'running',
76         'enable'    => 'true'
77         )
78       }
79     end
80
81     context "with $service_ensure => 'stopped'" do
82       let (:params) {{ :service_ensure => 'stopped', }}
83       it { is_expected.to contain_service("httpd").with(
84         'ensure'    => 'stopped',
85         'enable'    => 'true'
86         )
87       }
88     end
89
90     context "with $service_ensure => 'UNDEF'" do
91       let (:params) {{ :service_ensure => 'UNDEF' }}
92       it { is_expected.to contain_service("httpd").without_ensure }
93     end
94
95     context "with $service_restart unset" do
96       it { is_expected.to contain_service("httpd").without_restart }
97     end
98
99     context "with $service_restart => '/usr/sbin/apachectl graceful'" do
100      let (:params) {{ :service_restart => '/usr/sbin/apachectl graceful' }}
101      it { is_expected.to contain_service("httpd").with(
102         'restart' => '/usr/sbin/apachectl graceful'
103       )
104      }
105     end
106   end
107
108
109   context "on a RedHat 5 OS, do not manage service" do
110     let :facts do
111       {
112         :osfamily               => 'RedHat',
113         :operatingsystemrelease => '5',
114         :concat_basedir         => '/dne',
115         :operatingsystem        => 'RedHat',
116         :id                     => 'root',
117         :kernel                 => 'Linux',
118         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
119         :is_pe                  => false,
120       }
121     end
122     let(:params) do
123       {
124         'service_ensure' => 'running',
125         'service_name'   => 'httpd',
126         'service_manage' => false
127       }
128     end
129     it 'should not manage the httpd service' do
130       subject.should_not contain_service('httpd')
131     end
132   end
133
134   context "on a FreeBSD 5 OS" do
135     let :facts do
136       {
137         :osfamily               => 'FreeBSD',
138         :operatingsystemrelease => '9',
139         :concat_basedir         => '/dne',
140         :operatingsystem        => 'FreeBSD',
141         :id                     => 'root',
142         :kernel                 => 'FreeBSD',
143         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
144         :is_pe                  => false,
145       }
146     end
147     it { is_expected.to contain_service("httpd").with(
148       'name'      => 'apache24',
149       'ensure'    => 'running',
150       'enable'    => 'true'
151       )
152     }
153   end
154
155   context "on a Gentoo OS" do
156     let :facts do
157       {
158         :osfamily               => 'Gentoo',
159         :operatingsystem        => 'Gentoo',
160         :operatingsystemrelease => '3.16.1-gentoo',
161         :concat_basedir         => '/dne',
162         :id                     => 'root',
163         :kernel                 => 'Linux',
164         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin',
165         :is_pe                  => false,
166       }
167     end
168     it { is_expected.to contain_service("httpd").with(
169       'name'      => 'apache2',
170       'ensure'    => 'running',
171       'enable'    => 'true'
172       )
173     }
174   end
175 end