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