Skip to content

Commit 48d6abd

Browse files
committed
Rewrite mod_jk specs to use inheritance
1 parent b2887d6 commit 48d6abd

File tree

1 file changed

+90
-138
lines changed

1 file changed

+90
-138
lines changed

spec/classes/mod/jk_spec.rb

Lines changed: 90 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,7 @@
6363
default_port = 80
6464
altern8_port = 8008
6565

66-
context 'RHEL 6 with only required facts and default parameters' do
67-
let(:facts) do
68-
{
69-
osfamily: 'RedHat',
70-
operatingsystem: 'RedHat',
71-
operatingsystemrelease: '6',
72-
ipaddress: default_ip,
73-
}
74-
end
75-
let(:pre_condition) do
76-
'include apache'
77-
end
78-
let(:params) do
79-
{
80-
logroot: '/var/log/httpd',
81-
}
82-
end
83-
let(:mod_dir) { mod_dir }
84-
85-
mod_dir = '/etc/httpd/conf.d'
86-
87-
it_behaves_like 'minimal resources', mod_dir
88-
it_behaves_like 'specific workers_file', mod_dir
89-
it { is_expected.to contain_apache__listen("#{default_ip}:#{default_port}") }
90-
it {
91-
verify_contents(catalogue, 'jk.conf', ['<IfModule jk_module>', '</IfModule>'])
92-
}
93-
end
94-
95-
context 'Debian 8 with only required facts and default parameters' do
66+
context 'Debian 8' do
9667
let(:facts) do
9768
{
9869
osfamily: 'Debian',
@@ -101,50 +72,32 @@
10172
ipaddress: default_ip,
10273
}
10374
end
104-
let(:pre_condition) do
105-
'include apache'
106-
end
107-
let(:params) do
108-
{
109-
logroot: '/var/log/apache2',
110-
}
111-
end
112-
let(:mod_dir) { mod_dir }
11375

114-
mod_dir = '/etc/apache2/mods-available'
76+
context 'with only required facts and default parameters' do
77+
let(:facts) { super().merge('ipaddress' => default_ip) }
78+
let(:pre_condition) do
79+
'include apache'
80+
end
81+
let(:params) do
82+
{
83+
logroot: '/var/log/apache2',
84+
}
85+
end
86+
let(:mod_dir) { mod_dir }
11587

116-
it_behaves_like 'minimal resources', mod_dir
117-
it_behaves_like 'specific workers_file', mod_dir
118-
it { is_expected.to contain_apache__listen("#{default_ip}:#{default_port}") }
119-
it { is_expected.to contain_package('libapache2-mod-jk') }
120-
it {
121-
verify_contents(catalogue, 'jk.conf', ['<IfModule jk_module>', '</IfModule>'])
122-
}
123-
end
88+
mod_dir = '/etc/apache2/mods-available'
12489

125-
context 'RHEL 6 with required facts and alternative IP' do
126-
let(:facts) do
127-
{
128-
osfamily: 'RedHat',
129-
operatingsystem: 'RedHat',
130-
operatingsystemrelease: '6',
131-
ipaddress: default_ip,
90+
it_behaves_like 'minimal resources', mod_dir
91+
it_behaves_like 'specific workers_file', mod_dir
92+
it { is_expected.to contain_apache__listen("#{default_ip}:#{default_port}") }
93+
it { is_expected.to contain_package('libapache2-mod-jk') }
94+
it {
95+
verify_contents(catalogue, 'jk.conf', ['<IfModule jk_module>', '</IfModule>'])
13296
}
13397
end
134-
let(:pre_condition) do
135-
'include apache'
136-
end
137-
let(:params) do
138-
{
139-
ip: altern8_ip,
140-
logroot: '/var/log/httpd',
141-
}
142-
end
143-
144-
it { is_expected.to contain_apache__listen("#{altern8_ip}:#{default_port}") }
14598
end
14699

147-
context 'RHEL 6 with required facts and alternative port' do
100+
context 'RHEL 6' do
148101
let(:facts) do
149102
{
150103
osfamily: 'RedHat',
@@ -158,89 +111,88 @@
158111
end
159112
let(:params) do
160113
{
161-
port: altern8_port,
162114
logroot: '/var/log/httpd',
163115
}
164116
end
165117

166-
it { is_expected.to contain_apache__listen("#{default_ip}:#{altern8_port}") }
167-
end
118+
context 'with required facts' do
119+
let(:facts) { super().merge('ipaddress' => default_ip) }
168120

169-
context 'RHEL 6 with required facts and no binding' do
170-
let(:facts) do
171-
{
172-
osfamily: 'RedHat',
173-
operatingsystem: 'RedHat',
174-
operatingsystemrelease: '6',
175-
ipaddress: default_ip,
176-
}
177-
end
178-
let(:pre_condition) do
179-
'include apache'
180-
end
181-
let(:params) do
182-
{
183-
add_listen: false,
184-
logroot: '/var/log/httpd',
185-
}
186-
end
121+
context 'and default parameters' do
122+
let(:mod_dir) { mod_dir }
187123

188-
it { is_expected.not_to contain_apache__listen("#{default_ip}:#{default_port}") }
189-
end
124+
mod_dir = '/etc/httpd/conf.d'
190125

191-
{
192-
default: {
193-
shm_file: :undef,
194-
log_file: :undef,
195-
shm_path: '/var/log/httpd/jk-runtime-status',
196-
log_path: '/var/log/httpd/mod_jk.log',
197-
},
198-
relative: {
199-
shm_file: 'shm_file',
200-
log_file: 'log_file',
201-
shm_path: '/var/log/httpd/shm_file',
202-
log_path: '/var/log/httpd/log_file',
203-
},
204-
absolute: {
205-
shm_file: '/run/shm_file',
206-
log_file: '/tmp/log_file',
207-
shm_path: '/run/shm_file',
208-
log_path: '/tmp/log_file',
209-
},
210-
pipe: {
211-
shm_file: :undef,
212-
log_file: '"|rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400 -180"',
213-
shm_path: '/var/log/httpd/jk-runtime-status',
214-
log_path: '"|rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400 -180"',
215-
},
216-
}.each do |option, paths|
217-
context "RHEL 6 with #{option} shm_file and log_file paths" do
218-
let(:facts) do
219-
{
220-
osfamily: 'RedHat',
221-
operatingsystem: 'RedHat',
222-
operatingsystemrelease: '6',
126+
it_behaves_like 'minimal resources', mod_dir
127+
it_behaves_like 'specific workers_file', mod_dir
128+
it { is_expected.to contain_apache__listen("#{default_ip}:#{default_port}") }
129+
it {
130+
verify_contents(catalogue, 'jk.conf', ['<IfModule jk_module>', '</IfModule>'])
223131
}
224132
end
225-
let(:pre_condition) do
226-
'include apache'
133+
134+
context 'and alternative IP' do
135+
let(:params) { super().merge(ip: altern8_ip) }
136+
137+
it { is_expected.to contain_apache__listen("#{altern8_ip}:#{default_port}") }
227138
end
228-
let(:params) do
229-
{
230-
logroot: '/var/log/httpd',
231-
shm_file: paths[:shm_file],
232-
log_file: paths[:log_file],
233-
}
139+
140+
context 'and alternative port' do
141+
let(:params) { super().merge(port: altern8_port) }
142+
143+
it { is_expected.to contain_apache__listen("#{default_ip}:#{altern8_port}") }
234144
end
235145

236-
expected = "# This file is generated automatically by Puppet - DO NOT EDIT\n"\
237-
"# Any manual changes will be overwritten\n"\
238-
"\n"\
239-
"<IfModule jk_module>\n"\
240-
" JkShmFile #{paths[:shm_path]}\n"\
241-
" JkLogFile #{paths[:log_path]}\n"\
242-
"</IfModule>\n"
243-
it { is_expected.to contain_file('jk.conf').with_content(expected) }
146+
context 'no binding' do
147+
let(:params) { super().merge(add_listen: false) }
148+
149+
it { is_expected.not_to contain_apache__listen("#{default_ip}:#{default_port}") }
150+
end
151+
152+
{
153+
default: {
154+
shm_file: :undef,
155+
log_file: :undef,
156+
shm_path: '/var/log/httpd/jk-runtime-status',
157+
log_path: '/var/log/httpd/mod_jk.log',
158+
},
159+
relative: {
160+
shm_file: 'shm_file',
161+
log_file: 'log_file',
162+
shm_path: '/var/log/httpd/shm_file',
163+
log_path: '/var/log/httpd/log_file',
164+
},
165+
absolute: {
166+
shm_file: '/run/shm_file',
167+
log_file: '/tmp/log_file',
168+
shm_path: '/run/shm_file',
169+
log_path: '/tmp/log_file',
170+
},
171+
pipe: {
172+
shm_file: :undef,
173+
log_file: '"|rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400 -180"',
174+
shm_path: '/var/log/httpd/jk-runtime-status',
175+
log_path: '"|rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400 -180"',
176+
},
177+
}.each do |option, paths|
178+
context "#{option} shm_file and log_file paths" do
179+
let(:params) do
180+
super().merge(
181+
shm_file: paths[:shm_file],
182+
log_file: paths[:log_file],
183+
)
184+
end
185+
186+
expected = "# This file is generated automatically by Puppet - DO NOT EDIT\n"\
187+
"# Any manual changes will be overwritten\n"\
188+
"\n"\
189+
"<IfModule jk_module>\n"\
190+
" JkShmFile #{paths[:shm_path]}\n"\
191+
" JkLogFile #{paths[:log_path]}\n"\
192+
"</IfModule>\n"
193+
it { is_expected.to contain_file('jk.conf').with_content(expected) }
194+
end
195+
end
244196
end
245197
end
246198
end

0 commit comments

Comments
 (0)