]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/acceptance/mod_pagespeed_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / acceptance / mod_pagespeed_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apache::mod::pagespeed class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4   case fact('osfamily')
5   when 'Debian'
6     vhost_dir    = '/etc/apache2/sites-enabled'
7     mod_dir      = '/etc/apache2/mods-available'
8     service_name = 'apache2'
9   when 'RedHat'
10     vhost_dir    = '/etc/httpd/conf.d'
11     mod_dir      = '/etc/httpd/conf.d'
12     service_name = 'httpd'
13   when 'FreeBSD'
14     vhost_dir    = '/usr/local/etc/apache24/Vhosts'
15     mod_dir      = '/usr/local/etc/apache24/Modules'
16     service_name = 'apache24'
17   when 'Gentoo'
18     vhost_dir    = '/etc/apache2/vhosts.d'
19     mod_dir      = '/etc/apache2/modules.d'
20     service_name = 'apache2'
21   end
22
23   context "default pagespeed config" do
24     it 'succeeds in puppeting pagespeed' do
25       pp= <<-EOS
26         if $::osfamily == 'Debian' {
27           class { 'apt': }
28
29           apt::source { 'mod-pagespeed':
30             key         => '7FAC5991',
31             key_server  => 'pgp.mit.edu',
32             location    => 'http://dl.google.com/linux/mod-pagespeed/deb/',
33             release     => 'stable',
34             repos       => 'main',
35             include_src => false,
36             before      => Class['apache'],
37           }
38         } elsif $::osfamily == 'RedHat' {
39          yumrepo { 'mod-pagespeed':
40           baseurl  => "http://dl.google.com/linux/mod-pagespeed/rpm/stable/$::architecture",
41             enabled  => 1,
42             gpgcheck => 1,
43             gpgkey   => 'https://dl-ssl.google.com/linux/linux_signing_key.pub',
44             before   => Class['apache'],
45           }
46         }
47
48         class { 'apache':
49           mpm_module => 'prefork',
50         }
51         class { 'apache::mod::pagespeed':
52           enable_filters  => ['remove_comments'],
53           disable_filters => ['extend_cache'],
54           forbid_filters  => ['rewrite_javascript'],
55         }
56         apache::vhost { 'pagespeed.example.com':
57           port    => '80',
58           docroot => '/var/www/pagespeed',
59         }
60         host { 'pagespeed.example.com': ip => '127.0.0.1', }
61         file { '/var/www/pagespeed/index.html':
62           ensure  => file,
63           content => "<html>\n<!-- comment -->\n<body>\n<p>Hello World!</p>\n</body>\n</html>",
64         }
65       EOS
66       apply_manifest(pp, :catch_failures => true)
67     end
68
69     describe service(service_name) do
70       it { is_expected.to be_enabled }
71       it { is_expected.to be_running }
72     end
73
74     describe file("#{mod_dir}/pagespeed.conf") do
75       it { is_expected.to contain "AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html" }
76       it { is_expected.to contain "ModPagespeedEnableFilters remove_comments" }
77       it { is_expected.to contain "ModPagespeedDisableFilters extend_cache" }
78       it { is_expected.to contain "ModPagespeedForbidFilters rewrite_javascript" }
79     end
80
81     it 'should answer to pagespeed.example.com and include <head/> and be stripped of comments by mod_pagespeed' do
82       shell("/usr/bin/curl pagespeed.example.com:80") do |r|
83         expect(r.stdout).to match(/<head\/>/)
84         expect(r.stdout).not_to match(/<!-- comment -->/)
85         expect(r.exit_code).to eq(0)
86       end
87     end
88   end
89 end