File: mod_pagespeed_spec.rb

package info (click to toggle)
puppet-module-puppetlabs-apache 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,344 kB
  • ctags: 30
  • sloc: ruby: 6,274; sh: 44; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download
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
require 'spec_helper_acceptance'

describe 'apache::mod::pagespeed class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
  case fact('osfamily')
  when 'Debian'
    vhost_dir    = '/etc/apache2/sites-enabled'
    mod_dir      = '/etc/apache2/mods-available'
    service_name = 'apache2'
  when 'RedHat'
    vhost_dir    = '/etc/httpd/conf.d'
    mod_dir      = '/etc/httpd/conf.d'
    service_name = 'httpd'
  when 'FreeBSD'
    vhost_dir    = '/usr/local/etc/apache22/Vhosts'
    mod_dir      = '/usr/local/etc/apache22/Modules'
    service_name = 'apache22'
  end

  context "default pagespeed config" do
    it 'succeeds in puppeting pagespeed' do
      pp= <<-EOS
        if $::osfamily == 'Debian' {
          class { 'apt': }

          apt::source { 'mod-pagespeed':
            key         => '7FAC5991',
            key_server  => 'pgp.mit.edu',
            location    => 'http://dl.google.com/linux/mod-pagespeed/deb/',
            release     => 'stable',
            repos       => 'main',
            include_src => false,
            before      => Class['apache'],
          } 
        } elsif $::osfamily == 'RedHat' {
         yumrepo { 'mod-pagespeed':
          baseurl  => "http://dl.google.com/linux/mod-pagespeed/rpm/stable/$::architecture",
            enabled  => 1,
            gpgcheck => 1,
            gpgkey   => 'https://dl-ssl.google.com/linux/linux_signing_key.pub',
            before   => Class['apache'],
          }
        }

        class { 'apache':
          mpm_module => 'prefork',
        }
        class { 'apache::mod::pagespeed':
          enable_filters  => ['remove_comments'],
          disable_filters => ['extend_cache'],
          forbid_filters  => ['rewrite_javascript'],
        }
        apache::vhost { 'pagespeed.example.com':
          port    => '80',
          docroot => '/var/www/pagespeed',
        }
        host { 'pagespeed.example.com': ip => '127.0.0.1', }
        file { '/var/www/pagespeed/index.html':
          ensure  => file,
          content => "<html>\n<!-- comment -->\n<body>\n<p>Hello World!</p>\n</body>\n</html>",
        }
      EOS
      apply_manifest(pp, :catch_failures => true)
    end

    describe service(service_name) do
      it { should be_enabled }
      it { should be_running }
    end

    describe file("#{mod_dir}/pagespeed.conf") do
      it { should contain "AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html" }
      it { should contain "ModPagespeedEnableFilters remove_comments" }
      it { should contain "ModPagespeedDisableFilters extend_cache" }
      it { should contain "ModPagespeedForbidFilters rewrite_javascript" }
    end

    it 'should answer to pagespeed.example.com and include <head/> and be stripped of comments by mod_pagespeed' do
      shell("/usr/bin/curl pagespeed.example.com:80") do |r|
        r.stdout.should =~ /<head\/>/
        r.stdout.should_not =~ /<!-- comment -->/
        r.exit_code.should == 0
      end
    end
  end
end