]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/classes/apache_spec.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / apache / spec / classes / apache_spec.rb
1 require 'spec_helper'
2
3 describe 'apache', :type => :class do
4   context "on a Debian OS" do
5     let :facts do
6       {
7         :id                     => 'root',
8         :kernel                 => 'Linux',
9         :lsbdistcodename        => 'squeeze',
10         :osfamily               => 'Debian',
11         :operatingsystem        => 'Debian',
12         :operatingsystemrelease => '6',
13         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
14         :concat_basedir         => '/dne',
15         :is_pe                  => false,
16       }
17     end
18     it { is_expected.to contain_class("apache::params") }
19     it { is_expected.to contain_package("httpd").with(
20       'notify' => 'Class[Apache::Service]',
21       'ensure' => 'installed'
22       )
23     }
24     it { is_expected.to contain_user("www-data") }
25     it { is_expected.to contain_group("www-data") }
26     it { is_expected.to contain_class("apache::service") }
27     it { is_expected.to contain_file("/var/www").with(
28       'ensure'  => 'directory'
29       )
30     }
31     it { is_expected.to contain_file("/etc/apache2/sites-enabled").with(
32       'ensure'  => 'directory',
33       'recurse' => 'true',
34       'purge'   => 'true',
35       'notify'  => 'Class[Apache::Service]',
36       'require' => 'Package[httpd]'
37       )
38     }
39     it { is_expected.to contain_file("/etc/apache2/mods-enabled").with(
40       'ensure'  => 'directory',
41       'recurse' => 'true',
42       'purge'   => 'true',
43       'notify'  => 'Class[Apache::Service]',
44       'require' => 'Package[httpd]'
45       )
46     }
47     it { is_expected.to contain_file("/etc/apache2/mods-available").with(
48       'ensure'  => 'directory',
49       'recurse' => 'true',
50       'purge'   => 'false',
51       'notify'  => 'Class[Apache::Service]',
52       'require' => 'Package[httpd]'
53       )
54     }
55     it { is_expected.to contain_concat("/etc/apache2/ports.conf").with(
56       'owner'   => 'root',
57       'group'   => 'root',
58       'mode'    => '0644',
59       'notify'  => 'Class[Apache::Service]'
60       )
61     }
62     # Assert that load files are placed and symlinked for these mods, but no conf file.
63     [
64       'auth_basic',
65       'authn_file',
66       'authz_default',
67       'authz_groupfile',
68       'authz_host',
69       'authz_user',
70       'dav',
71       'env'
72     ].each do |modname|
73       it { is_expected.to contain_file("#{modname}.load").with(
74         'path'   => "/etc/apache2/mods-available/#{modname}.load",
75         'ensure' => 'file'
76       ) }
77       it { is_expected.to contain_file("#{modname}.load symlink").with(
78         'path'   => "/etc/apache2/mods-enabled/#{modname}.load",
79         'ensure' => 'link',
80         'target' => "/etc/apache2/mods-available/#{modname}.load"
81       ) }
82       it { is_expected.not_to contain_file("#{modname}.conf") }
83       it { is_expected.not_to contain_file("#{modname}.conf symlink") }
84     end
85
86     context "with Apache version < 2.4" do
87       let :params do
88         { :apache_version => '2.2' }
89       end
90
91       it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^Include "/etc/apache2/conf\.d/\*\.conf"$} }
92     end
93
94     context "with Apache version >= 2.4" do
95       let :params do
96         {
97           :apache_version => '2.4',
98           :use_optional_includes => true
99         }
100       end
101
102       it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^IncludeOptional "/etc/apache2/conf\.d/\*\.conf"$} }
103     end
104
105     context "when specifying slash encoding behaviour" do
106       let :params do
107         { :allow_encoded_slashes => 'nodecode' }
108       end
109
110       it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^AllowEncodedSlashes nodecode$} }
111     end
112
113     context "when specifying default character set" do
114       let :params do
115         { :default_charset => 'none' }
116       end
117
118       it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^AddDefaultCharset none$} }
119     end
120
121     # Assert that both load files and conf files are placed and symlinked for these mods
122     [
123       'alias',
124       'autoindex',
125       'dav_fs',
126       'deflate',
127       'dir',
128       'mime',
129       'negotiation',
130       'setenvif',
131     ].each do |modname|
132       it { is_expected.to contain_file("#{modname}.load").with(
133         'path'   => "/etc/apache2/mods-available/#{modname}.load",
134         'ensure' => 'file'
135       ) }
136       it { is_expected.to contain_file("#{modname}.load symlink").with(
137         'path'   => "/etc/apache2/mods-enabled/#{modname}.load",
138         'ensure' => 'link',
139         'target' => "/etc/apache2/mods-available/#{modname}.load"
140       ) }
141       it { is_expected.to contain_file("#{modname}.conf").with(
142         'path'   => "/etc/apache2/mods-available/#{modname}.conf",
143         'ensure' => 'file'
144       ) }
145       it { is_expected.to contain_file("#{modname}.conf symlink").with(
146         'path'   => "/etc/apache2/mods-enabled/#{modname}.conf",
147         'ensure' => 'link',
148         'target' => "/etc/apache2/mods-available/#{modname}.conf"
149       ) }
150     end
151
152     describe "Check default type" do
153       context "with Apache version < 2.4" do
154         let :params do
155           {
156             :apache_version => '2.2',
157           }
158         end
159     
160        context "when default_type => 'none'" do
161           let :params do
162             { :default_type => 'none' }
163           end
164     
165           it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^DefaultType none$} }
166         end
167         context "when default_type => 'text/plain'" do
168           let :params do
169             { :default_type => 'text/plain' }
170           end
171     
172           it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^DefaultType text/plain$} }
173         end
174       end
175    
176       context "with Apache version >= 2.4" do
177         let :params do
178           {
179             :apache_version => '2.4',
180           }
181         end
182         it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^DefaultType [.]*$} }
183       end
184     end
185
186     describe "Don't create user resource" do
187       context "when parameter manage_user is false" do
188         let :params do
189           { :manage_user => false }
190         end
191
192         it { is_expected.not_to contain_user('www-data') }
193         it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^User www-data\n} }
194       end
195     end
196     describe "Don't create group resource" do
197       context "when parameter manage_group is false" do
198         let :params do
199           { :manage_group => false }
200         end
201
202         it { is_expected.not_to contain_group('www-data') }
203         it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^Group www-data\n} }
204       end
205     end
206
207     describe "Add extra LogFormats" do
208       context "When parameter log_formats is a hash" do
209         let :params do
210           { :log_formats => {
211             'vhost_common'   => "%v %h %l %u %t \"%r\" %>s %b",
212             'vhost_combined' => "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
213           } }
214         end
215
216         it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common\n} }
217         it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" vhost_combined\n} }
218       end
219     end
220
221     describe "Override existing LogFormats" do
222       context "When parameter log_formats is a hash" do
223         let :params do
224           { :log_formats => {
225             'common'   => "%v %h %l %u %t \"%r\" %>s %b",
226             'combined' => "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
227           } }
228         end
229
230         it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n} }
231         it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
232         it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n} }
233         it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
234         it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
235       end
236     end
237
238     context "on Ubuntu" do
239       let :facts do
240         super().merge({
241           :operatingsystem => 'Ubuntu'
242         })
243       end
244
245       context "13.10" do
246         let :facts do
247           super().merge({
248             :lsbdistrelease         => '13.10',
249             :operatingsystemrelease => '13.10'
250           })
251         end
252         it { is_expected.to contain_class('apache').with_apache_version('2.4') }
253       end
254       context "12.04" do
255         let :facts do
256           super().merge({
257             :lsbdistrelease         => '12.04',
258             :operatingsystemrelease => '12.04'
259           })
260         end
261         it { is_expected.to contain_class('apache').with_apache_version('2.2') }
262       end
263       context "13.04" do
264         let :facts do
265           super().merge({
266             :lsbdistrelease         => '13.04',
267             :operatingsystemrelease => '13.04'
268           })
269         end
270         it { is_expected.to contain_class('apache').with_apache_version('2.2') }
271       end
272     end
273   end
274   context "on a RedHat 5 OS" do
275     let :facts do
276       {
277         :id                     => 'root',
278         :kernel                 => 'Linux',
279         :osfamily               => 'RedHat',
280         :operatingsystem        => 'RedHat',
281         :operatingsystemrelease => '5',
282         :concat_basedir         => '/dne',
283         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
284         :is_pe                  => false,
285       }
286     end
287     it { is_expected.to contain_class("apache::params") }
288     it { is_expected.to contain_package("httpd").with(
289       'notify' => 'Class[Apache::Service]',
290       'ensure' => 'installed'
291       )
292     }
293     it { is_expected.to contain_user("apache") }
294     it { is_expected.to contain_group("apache") }
295     it { is_expected.to contain_class("apache::service") }
296     it { is_expected.to contain_file("/var/www/html").with(
297       'ensure'  => 'directory'
298       )
299     }
300     it { is_expected.to contain_file("/etc/httpd/conf.d").with(
301       'ensure'  => 'directory',
302       'recurse' => 'true',
303       'purge'   => 'true',
304       'notify'  => 'Class[Apache::Service]',
305       'require' => 'Package[httpd]'
306       )
307     }
308     it { is_expected.to contain_concat("/etc/httpd/conf/ports.conf").with(
309       'owner'   => 'root',
310       'group'   => 'root',
311       'mode'    => '0644',
312       'notify'  => 'Class[Apache::Service]'
313       )
314     }
315     describe "Alternate confd/mod/vhosts directory" do
316       let :params do
317         {
318           :vhost_dir => '/etc/httpd/site.d',
319           :confd_dir => '/etc/httpd/conf.d',
320           :mod_dir   => '/etc/httpd/mod.d',
321         }
322       end
323
324       ['mod.d','site.d','conf.d'].each do |dir|
325         it { is_expected.to contain_file("/etc/httpd/#{dir}").with(
326           'ensure'  => 'directory',
327           'recurse' => 'true',
328           'purge'   => 'true',
329           'notify'  => 'Class[Apache::Service]',
330           'require' => 'Package[httpd]'
331         ) }
332       end
333
334       # Assert that load files are placed for these mods, but no conf file.
335       [
336         'auth_basic',
337         'authn_file',
338         'authz_default',
339         'authz_groupfile',
340         'authz_host',
341         'authz_user',
342         'dav',
343         'env',
344       ].each do |modname|
345         it { is_expected.to contain_file("#{modname}.load").with_path(
346           "/etc/httpd/mod.d/#{modname}.load"
347         ) }
348         it { is_expected.not_to contain_file("#{modname}.conf").with_path(
349           "/etc/httpd/mod.d/#{modname}.conf"
350         ) }
351       end
352
353       # Assert that both load files and conf files are placed for these mods
354       [
355         'alias',
356         'autoindex',
357         'dav_fs',
358         'deflate',
359         'dir',
360         'mime',
361         'negotiation',
362         'setenvif',
363       ].each do |modname|
364         it { is_expected.to contain_file("#{modname}.load").with_path(
365           "/etc/httpd/mod.d/#{modname}.load"
366         ) }
367         it { is_expected.to contain_file("#{modname}.conf").with_path(
368           "/etc/httpd/mod.d/#{modname}.conf"
369         ) }
370       end
371
372       context "with Apache version < 2.4" do
373         let :params do
374           { :apache_version => '2.2' }
375         end
376
377         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/conf\.d/\*\.conf"$} }
378       end
379
380       context "with Apache version >= 2.4" do
381         let :params do
382           {
383             :apache_version => '2.4',
384             :use_optional_includes => true
385           }
386         end
387
388         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^IncludeOptional "/etc/httpd/conf\.d/\*\.conf"$} }
389       end
390
391       context "when specifying slash encoding behaviour" do
392         let :params do
393           { :allow_encoded_slashes => 'nodecode' }
394         end
395
396         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^AllowEncodedSlashes nodecode$} }
397       end
398
399       context "when specifying default character set" do
400         let :params do
401           { :default_charset => 'none' }
402         end
403
404         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^AddDefaultCharset none$} }
405       end
406
407       context "with Apache version < 2.4" do
408         let :params do
409           {
410             :apache_version => '2.2',
411           }
412         end
413
414        context "when default_type => 'none'" do
415           let :params do
416             { :default_type => 'none' }
417           end
418
419           it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^DefaultType none$} }
420         end
421         context "when default_type => 'text/plain'" do
422           let :params do
423             { :default_type => 'text/plain' }
424           end
425
426           it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^DefaultType text/plain$} }
427         end
428       end
429
430       context "with Apache version >= 2.4" do
431         let :params do
432           {
433             :apache_version => '2.4',
434           }
435         end
436         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").without_content %r{^DefaultType [.]*$} }
437       end
438
439       it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/site\.d/\*"$} }
440       it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/mod\.d/\*\.conf"$} }
441       it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/mod\.d/\*\.load"$} }
442     end
443
444     describe "Alternate conf directory" do
445       let :params do
446         { :conf_dir => '/opt/rh/root/etc/httpd/conf' }
447       end
448
449       it { is_expected.to contain_file("/opt/rh/root/etc/httpd/conf/httpd.conf").with(
450         'ensure'  => 'file',
451         'notify'  => 'Class[Apache::Service]',
452         'require' => 'Package[httpd]'
453       ) }
454     end
455
456     describe "Alternate conf.d directory" do
457       let :params do
458         { :confd_dir => '/etc/httpd/special_conf.d' }
459       end
460
461       it { is_expected.to contain_file("/etc/httpd/special_conf.d").with(
462         'ensure'  => 'directory',
463         'recurse' => 'true',
464         'purge'   => 'true',
465         'notify'  => 'Class[Apache::Service]',
466         'require' => 'Package[httpd]'
467       ) }
468     end
469
470     describe "Alternate mpm_modules" do
471       context "when declaring mpm_module is false" do
472         let :params do
473           { :mpm_module => false }
474         end
475         it 'should not declare mpm modules' do
476           is_expected.not_to contain_class('apache::mod::event')
477           is_expected.not_to contain_class('apache::mod::itk')
478           is_expected.not_to contain_class('apache::mod::peruser')
479           is_expected.not_to contain_class('apache::mod::prefork')
480           is_expected.not_to contain_class('apache::mod::worker')
481         end
482       end
483       context "when declaring mpm_module => prefork" do
484         let :params do
485           { :mpm_module => 'prefork' }
486         end
487         it { is_expected.to contain_class('apache::mod::prefork') }
488         it { is_expected.not_to contain_class('apache::mod::event') }
489         it { is_expected.not_to contain_class('apache::mod::itk') }
490         it { is_expected.not_to contain_class('apache::mod::peruser') }
491         it { is_expected.not_to contain_class('apache::mod::worker') }
492       end
493       context "when declaring mpm_module => worker" do
494         let :params do
495           { :mpm_module => 'worker' }
496         end
497         it { is_expected.to contain_class('apache::mod::worker') }
498         it { is_expected.not_to contain_class('apache::mod::event') }
499         it { is_expected.not_to contain_class('apache::mod::itk') }
500         it { is_expected.not_to contain_class('apache::mod::peruser') }
501         it { is_expected.not_to contain_class('apache::mod::prefork') }
502       end
503       context "when declaring mpm_module => breakme" do
504         let :params do
505           { :mpm_module => 'breakme' }
506         end
507         it { expect { catalogue }.to raise_error Puppet::Error, /does not match/ }
508       end
509     end
510
511     describe "different templates for httpd.conf" do
512       context "with default" do
513         let :params do
514           { :conf_template => 'apache/httpd.conf.erb' }
515         end
516         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^# Security\n} }
517       end
518       context "with non-default" do
519         let :params do
520           { :conf_template => 'site_apache/fake.conf.erb' }
521         end
522         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Fake template for rspec.$} }
523       end
524     end
525
526     describe "default mods" do
527       context "without" do
528         let :params do
529           { :default_mods => false }
530         end
531
532         it { is_expected.to contain_apache__mod('authz_host') }
533         it { is_expected.not_to contain_apache__mod('env') }
534       end
535       context "custom" do
536         let :params do
537           { :default_mods => [
538             'info',
539             'alias',
540             'mime',
541             'env',
542             'setenv',
543             'expires',
544           ]}
545         end
546
547         it { is_expected.to contain_apache__mod('authz_host') }
548         it { is_expected.to contain_apache__mod('env') }
549         it { is_expected.to contain_class('apache::mod::info') }
550         it { is_expected.to contain_class('apache::mod::mime') }
551       end
552     end
553     describe "Don't create user resource" do
554       context "when parameter manage_user is false" do
555         let :params do
556           { :manage_user => false }
557         end
558
559         it { is_expected.not_to contain_user('apache') }
560         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^User apache\n} }
561       end
562     end
563     describe "Don't create group resource" do
564       context "when parameter manage_group is false" do
565         let :params do
566           { :manage_group => false }
567         end
568
569         it { is_expected.not_to contain_group('apache') }
570         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Group apache\n} }
571
572       end
573     end
574     describe "sendfile" do
575       context "with invalid value" do
576         let :params do
577           { :sendfile => 'foo' }
578         end
579         it "should fail" do
580           expect do
581             catalogue
582           end.to raise_error(Puppet::Error, /"foo" does not match/)
583         end
584       end
585       context "On" do
586         let :params do
587           { :sendfile => 'On' }
588         end
589         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^EnableSendfile On\n} }
590       end
591       context "Off" do
592         let :params do
593           { :sendfile => 'Off' }
594         end
595         it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^EnableSendfile Off\n} }
596       end
597     end
598     context "on Fedora" do
599       let :facts do
600         super().merge({
601           :operatingsystem => 'Fedora'
602         })
603       end
604
605       context "21" do
606         let :facts do
607           super().merge({
608             :lsbdistrelease         => '21',
609             :operatingsystemrelease => '21'
610           })
611         end
612         it { is_expected.to contain_class('apache').with_apache_version('2.4') }
613       end
614       context "Rawhide" do
615         let :facts do
616           super().merge({
617             :lsbdistrelease         => 'Rawhide',
618             :operatingsystemrelease => 'Rawhide'
619           })
620         end
621         it { is_expected.to contain_class('apache').with_apache_version('2.4') }
622       end
623       # kinda obsolete
624       context "17" do
625         let :facts do
626           super().merge({
627             :lsbdistrelease         => '17',
628             :operatingsystemrelease => '17'
629           })
630         end
631         it { is_expected.to contain_class('apache').with_apache_version('2.2') }
632       end
633     end
634   end
635   context "on a FreeBSD OS" do
636     let :facts do
637       {
638         :id                     => 'root',
639         :kernel                 => 'FreeBSD',
640         :osfamily               => 'FreeBSD',
641         :operatingsystem        => 'FreeBSD',
642         :operatingsystemrelease => '10',
643         :concat_basedir         => '/dne',
644         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
645         :is_pe                  => false,
646       }
647     end
648     it { is_expected.to contain_class("apache::params") }
649     it { is_expected.to contain_class("apache::package").with({'ensure' => 'present'}) }
650     it { is_expected.to contain_user("www") }
651     it { is_expected.to contain_group("www") }
652     it { is_expected.to contain_class("apache::service") }
653     it { is_expected.to contain_file("/usr/local/www/apache24/data").with(
654       'ensure'  => 'directory'
655       )
656     }
657     it { is_expected.to contain_file("/usr/local/etc/apache24/Vhosts").with(
658       'ensure'  => 'directory',
659       'recurse' => 'true',
660       'purge'   => 'true',
661       'notify'  => 'Class[Apache::Service]',
662       'require' => 'Package[httpd]'
663     ) }
664     it { is_expected.to contain_file("/usr/local/etc/apache24/Modules").with(
665       'ensure'  => 'directory',
666       'recurse' => 'true',
667       'purge'   => 'true',
668       'notify'  => 'Class[Apache::Service]',
669       'require' => 'Package[httpd]'
670     ) }
671     it { is_expected.to contain_concat("/usr/local/etc/apache24/ports.conf").with(
672       'owner'   => 'root',
673       'group'   => 'wheel',
674       'mode'    => '0644',
675       'notify'  => 'Class[Apache::Service]'
676     ) }
677     # Assert that load files are placed for these mods, but no conf file.
678     [
679       'auth_basic',
680       'authn_core',
681       'authn_file',
682       'authz_groupfile',
683       'authz_host',
684       'authz_user',
685       'dav',
686       'env'
687     ].each do |modname|
688       it { is_expected.to contain_file("#{modname}.load").with(
689         'path'   => "/usr/local/etc/apache24/Modules/#{modname}.load",
690         'ensure' => 'file'
691       ) }
692       it { is_expected.not_to contain_file("#{modname}.conf") }
693     end
694
695     # Assert that both load files and conf files are placed for these mods
696     [
697       'alias',
698       'autoindex',
699       'dav_fs',
700       'deflate',
701       'dir',
702       'mime',
703       'negotiation',
704       'setenvif',
705     ].each do |modname|
706       it { is_expected.to contain_file("#{modname}.load").with(
707         'path'   => "/usr/local/etc/apache24/Modules/#{modname}.load",
708         'ensure' => 'file'
709       ) }
710       it { is_expected.to contain_file("#{modname}.conf").with(
711         'path'   => "/usr/local/etc/apache24/Modules/#{modname}.conf",
712         'ensure' => 'file'
713       ) }
714     end
715   end
716   context "on a Gentoo OS" do
717     let :facts do
718       {
719         :id                     => 'root',
720         :kernel                 => 'Linux',
721         :osfamily               => 'Gentoo',
722         :operatingsystem        => 'Gentoo',
723         :operatingsystemrelease => '3.16.1-gentoo',
724         :concat_basedir         => '/dne',
725         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin',
726         :is_pe                  => false,
727       }
728     end
729     it { is_expected.to contain_class("apache::params") }
730     it { is_expected.to contain_user("apache") }
731     it { is_expected.to contain_group("apache") }
732     it { is_expected.to contain_class("apache::service") }
733     it { is_expected.to contain_file("/var/www/localhost/htdocs").with(
734       'ensure'  => 'directory'
735       )
736     }
737     it { is_expected.to contain_file("/etc/apache2/vhosts.d").with(
738       'ensure'  => 'directory',
739       'recurse' => 'true',
740       'purge'   => 'true',
741       'notify'  => 'Class[Apache::Service]',
742       'require' => 'Package[httpd]'
743     ) }
744     it { is_expected.to contain_file("/etc/apache2/modules.d").with(
745       'ensure'  => 'directory',
746       'recurse' => 'true',
747       'purge'   => 'true',
748       'notify'  => 'Class[Apache::Service]',
749       'require' => 'Package[httpd]'
750     ) }
751     it { is_expected.to contain_concat("/etc/apache2/ports.conf").with(
752       'owner'   => 'root',
753       'group'   => 'wheel',
754       'mode'    => '0644',
755       'notify'  => 'Class[Apache::Service]'
756     ) }
757   end
758   context 'on all OSes' do
759     let :facts do
760       {
761         :id                     => 'root',
762         :kernel                 => 'Linux',
763         :osfamily               => 'RedHat',
764         :operatingsystem        => 'RedHat',
765         :operatingsystemrelease => '6',
766         :concat_basedir         => '/dne',
767         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
768         :is_pe                  => false,
769       }
770     end
771     context 'with a custom apache_name parameter' do
772       let :params do {
773         :apache_name => 'httpd24-httpd'
774       }
775       end
776       it { is_expected.to contain_package("httpd").with(
777         'notify' => 'Class[Apache::Service]',
778         'ensure' => 'installed',
779         'name'   => 'httpd24-httpd'
780         )
781       }
782     end
783     context 'default vhost defaults' do
784       it { is_expected.to contain_apache__vhost('default').with_ensure('present') }
785       it { is_expected.to contain_apache__vhost('default-ssl').with_ensure('absent') }
786     end
787     context 'without default non-ssl vhost' do
788       let :params do {
789         :default_vhost  => false
790       }
791       end
792       it { is_expected.to contain_apache__vhost('default').with_ensure('absent') }
793       it { is_expected.not_to contain_file('/var/www/html') }
794     end
795     context 'with default ssl vhost' do
796       let :params do {
797           :default_ssl_vhost  => true
798         }
799       end
800       it { is_expected.to contain_apache__vhost('default-ssl').with_ensure('present') }
801       it { is_expected.to contain_file('/var/www/html') }
802     end
803   end
804   context 'with unsupported osfamily' do
805     let :facts do
806       { :osfamily        => 'Darwin',
807         :operatingsystemrelease => '13.1.0',
808         :concat_basedir         => '/dne',
809         :is_pe                  => false,
810       }
811     end
812
813     it do
814       expect {
815        catalogue
816       }.to raise_error(Puppet::Error, /Unsupported osfamily/)
817     end
818   end
819 end