Skip to content

Commit b54431d

Browse files
author
sanfrancrisko
authored
Merge pull request #2120 from ekohl/use-shared-examples-for-facts
(MAINT) Use shared examples for facts + other spec cleanups
2 parents f1ad00d + 675ba83 commit b54431d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+619
-2696
lines changed

spec/classes/apache_spec.rb

Lines changed: 21 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@
44

55
describe 'apache', type: :class do
66
context 'on a Debian OS' do
7-
let :facts do
8-
{
9-
id: 'root',
10-
kernel: 'Linux',
11-
lsbdistcodename: 'squeeze',
12-
osfamily: 'Debian',
13-
operatingsystem: 'Debian',
14-
operatingsystemrelease: '6',
15-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
16-
is_pe: false,
17-
}
18-
end
7+
include_examples 'Debian 8'
198

209
it { is_expected.to contain_class('apache::params') }
2110
it {
@@ -28,7 +17,7 @@
2817
it { is_expected.to contain_group('www-data') }
2918
it { is_expected.to contain_class('apache::service') }
3019
it {
31-
is_expected.to contain_file('/var/www').with(
20+
is_expected.to contain_file('/var/www/html').with(
3221
'ensure' => 'directory',
3322
)
3423
}
@@ -57,7 +46,7 @@
5746
).that_notifies('Class[Apache::Service]')
5847
}
5948
# Assert that load files are placed and symlinked for these mods, but no conf file.
60-
['auth_basic', 'authn_file', 'authz_default', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname|
49+
['auth_basic', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname|
6150
it {
6251
is_expected.to contain_file("#{modname}.load").with(
6352
'path' => "/etc/apache2/mods-available/#{modname}.load",
@@ -243,33 +232,17 @@
243232
end
244233
end
245234

246-
context '8' do
247-
let :facts do
248-
super().merge(lsbdistcodename: 'jessie',
249-
operatingsystemrelease: '8.0.0')
235+
describe 'Alternate mpm_modules when declaring mpm_module => prefork' do
236+
let :params do
237+
{ mpm_module: 'worker' }
250238
end
251239

252-
it {
253-
is_expected.to contain_file('/var/www/html').with(
254-
'ensure' => 'directory',
255-
)
256-
}
257-
describe 'Alternate mpm_modules when declaring mpm_module => prefork' do
258-
let :params do
259-
{ mpm_module: 'worker' }
260-
end
261-
262-
it { is_expected.to contain_exec('/usr/sbin/a2dismod event') }
263-
it { is_expected.to contain_exec('/usr/sbin/a2dismod prefork') }
264-
end
240+
it { is_expected.to contain_exec('/usr/sbin/a2dismod event') }
241+
it { is_expected.to contain_exec('/usr/sbin/a2dismod prefork') }
265242
end
266243

267-
context 'on Ubuntu 14.04' do
268-
let :facts do
269-
super().merge(operatingsystem: 'Ubuntu',
270-
lsbdistrelease: '14.04',
271-
operatingsystemrelease: '14.04')
272-
end
244+
context 'on Ubuntu 18.04' do
245+
include_examples 'Ubuntu 18.04'
273246

274247
it {
275248
is_expected.to contain_file('/var/www/html').with(
@@ -279,18 +252,8 @@
279252
end
280253
end
281254

282-
context 'on a RedHat 5 OS' do
283-
let :facts do
284-
{
285-
id: 'root',
286-
kernel: 'Linux',
287-
osfamily: 'RedHat',
288-
operatingsystem: 'RedHat',
289-
operatingsystemrelease: '5',
290-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
291-
is_pe: false,
292-
}
293-
end
255+
context 'on a RedHat 8 OS' do
256+
include_examples 'RedHat 8'
294257

295258
it { is_expected.to contain_class('apache::params') }
296259
it {
@@ -338,7 +301,7 @@
338301
end
339302

340303
# Assert that load files are placed for these mods, but no conf file.
341-
['auth_basic', 'authn_file', 'authz_default', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname|
304+
['auth_basic', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname|
342305
it {
343306
is_expected.to contain_file("#{modname}.load").with_path(
344307
"/etc/httpd/mod.d/#{modname}.load",
@@ -365,7 +328,7 @@
365328
}
366329
end
367330

368-
it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/site\.d/\*"$} }
331+
it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^IncludeOptional "/etc/httpd/site\.d/\*"$} }
369332
it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/mod\.d/\*\.conf"$} }
370333
it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/mod\.d/\*\.load"$} }
371334
end
@@ -667,46 +630,24 @@
667630
end
668631

669632
context 'on Fedora 21' do
670-
let :facts do
671-
super().merge(operatingsystem: 'Fedora',
672-
lsbdistrelease: '21',
673-
operatingsystemrelease: '21')
674-
end
633+
include_examples 'Fedora 21'
675634

676635
it { is_expected.to contain_class('apache').with_apache_version('2.4') }
677636
end
678637
context 'on Fedora Rawhide' do
679-
let :facts do
680-
super().merge(operatingsystem: 'Fedora',
681-
lsbdistrelease: 'Rawhide',
682-
operatingsystemrelease: 'Rawhide')
683-
end
638+
include_examples 'Fedora Rawhide'
684639

685640
it { is_expected.to contain_class('apache').with_apache_version('2.4') }
686641
end
687642
# kinda obsolete
688643
context 'on Fedora 17' do
689-
let :facts do
690-
super().merge(operatingsystem: 'Fedora',
691-
lsbdistrelease: '17',
692-
operatingsystemrelease: '17')
693-
end
644+
include_examples 'Fedora 17'
694645

695646
it { is_expected.to contain_class('apache').with_apache_version('2.2') }
696647
end
697648
end
698649
context 'on a FreeBSD OS' do
699-
let :facts do
700-
{
701-
id: 'root',
702-
kernel: 'FreeBSD',
703-
osfamily: 'FreeBSD',
704-
operatingsystem: 'FreeBSD',
705-
operatingsystemrelease: '10',
706-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
707-
is_pe: false,
708-
}
709-
end
650+
include_examples 'FreeBSD 10'
710651

711652
it { is_expected.to contain_class('apache::params') }
712653
it { is_expected.to contain_class('apache::package').with('ensure' => 'present') }
@@ -764,17 +705,7 @@
764705
end
765706
end
766707
context 'on a Gentoo OS' do
767-
let :facts do
768-
{
769-
id: 'root',
770-
kernel: 'Linux',
771-
osfamily: 'Gentoo',
772-
operatingsystem: 'Gentoo',
773-
operatingsystemrelease: '3.16.1-gentoo',
774-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin',
775-
is_pe: false,
776-
}
777-
end
708+
include_examples 'Gentoo'
778709

779710
it { is_expected.to contain_class('apache::params') }
780711
it { is_expected.to contain_user('apache') }
@@ -805,17 +736,7 @@
805736
}
806737
end
807738
context 'on all OSes' do
808-
let :facts do
809-
{
810-
id: 'root',
811-
kernel: 'Linux',
812-
osfamily: 'RedHat',
813-
operatingsystem: 'RedHat',
814-
operatingsystemrelease: '6',
815-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
816-
is_pe: false,
817-
}
818-
end
739+
include_examples 'RedHat 6'
819740

820741
context 'with a custom apache_name parameter' do
821742
let :params do
@@ -900,11 +821,7 @@
900821
end
901822
end
902823
context 'with unsupported osfamily' do
903-
let :facts do
904-
{ osfamily: 'Darwin',
905-
operatingsystemrelease: '13.1.0',
906-
is_pe: false }
907-
end
824+
include_examples 'Darwin'
908825

909826
it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily}) }
910827
end

spec/classes/mod/alias_spec.rb

Lines changed: 9 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,25 @@
77

88
context 'default configuration with parameters' do
99
context 'on a Debian OS', :compile do
10-
let :facts do
11-
{
12-
id: 'root',
13-
kernel: 'Linux',
14-
lsbdistcodename: 'jessie',
15-
osfamily: 'Debian',
16-
operatingsystem: 'Debian',
17-
operatingsystemrelease: '8',
18-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
19-
is_pe: false,
20-
}
21-
end
10+
include_examples 'Debian 8'
2211

2312
it { is_expected.to contain_apache__mod('alias') }
2413
it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/share\/apache2\/icons\/"}) }
2514
end
2615
context 'on a RedHat 6-based OS', :compile do
27-
let :facts do
28-
{
29-
id: 'root',
30-
kernel: 'Linux',
31-
osfamily: 'RedHat',
32-
operatingsystem: 'RedHat',
33-
operatingsystemrelease: '6',
34-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
35-
is_pe: false,
36-
}
37-
end
16+
include_examples 'RedHat 6'
3817

3918
it { is_expected.to contain_apache__mod('alias') }
4019
it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/var\/www\/icons\/"}) }
4120
end
4221
context 'on a RedHat 7-based OS', :compile do
43-
let :facts do
44-
{
45-
id: 'root',
46-
kernel: 'Linux',
47-
osfamily: 'RedHat',
48-
operatingsystem: 'RedHat',
49-
operatingsystemrelease: '7',
50-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
51-
is_pe: false,
52-
}
53-
end
22+
include_examples 'RedHat 7'
5423

5524
it { is_expected.to contain_apache__mod('alias') }
5625
it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/share\/httpd\/icons\/"}) }
5726
end
5827
context 'on a RedHat 8-based OS', :compile do
59-
let :facts do
60-
{
61-
id: 'root',
62-
kernel: 'Linux',
63-
osfamily: 'RedHat',
64-
operatingsystem: 'RedHat',
65-
operatingsystemrelease: '8',
66-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
67-
is_pe: false,
68-
}
69-
end
28+
include_examples 'RedHat 8'
7029

7130
it { is_expected.to contain_apache__mod('alias') }
7231
it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/share\/httpd\/icons\/"}) }
@@ -75,62 +34,34 @@
7534
let :pre_condition do
7635
'class { apache: default_mods => false }'
7736
end
78-
let :facts do
79-
{
80-
id: 'root',
81-
kernel: 'Linux',
82-
osfamily: 'RedHat',
83-
operatingsystem: 'RedHat',
84-
operatingsystemrelease: '7',
85-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
86-
is_pe: false,
87-
}
88-
end
8937
let :params do
9038
{
9139
'icons_options' => 'foo',
9240
}
9341
end
9442

43+
include_examples 'RedHat 7'
44+
9545
it { is_expected.to contain_apache__mod('alias') }
9646
it { is_expected.to contain_file('alias.conf').with(content: %r{Options foo}) }
9747
end
9848
context 'with icons path change', :compile do
9949
let :pre_condition do
10050
'class { apache: default_mods => false }'
10151
end
102-
let :facts do
103-
{
104-
id: 'root',
105-
kernel: 'Linux',
106-
osfamily: 'RedHat',
107-
operatingsystem: 'RedHat',
108-
operatingsystemrelease: '7',
109-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
110-
is_pe: false,
111-
}
112-
end
11352
let :params do
11453
{
11554
'icons_prefix' => 'apache-icons',
11655
}
11756
end
11857

58+
include_examples 'RedHat 7'
59+
11960
it { is_expected.to contain_apache__mod('alias') }
12061
it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/apache-icons\/ "\/usr\/share\/httpd\/icons\/"}) }
12162
end
12263
context 'on a FreeBSD OS', :compile do
123-
let :facts do
124-
{
125-
id: 'root',
126-
kernel: 'FreeBSD',
127-
osfamily: 'FreeBSD',
128-
operatingsystem: 'FreeBSD',
129-
operatingsystemrelease: '10',
130-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
131-
is_pe: false,
132-
}
133-
end
64+
include_examples 'FreeBSD 10'
13465

13566
it { is_expected.to contain_apache__mod('alias') }
13667
it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/local\/www\/apache24\/icons\/"}) }

0 commit comments

Comments
 (0)