diff --git a/manifests/mod/disk_cache.pp b/manifests/mod/disk_cache.pp index 9d8c5e20..11a6531e 100644 --- a/manifests/mod/disk_cache.pp +++ b/manifests/mod/disk_cache.pp @@ -1,63 +1,63 @@ # @summary # Installs and configures `mod_disk_cache`. # # @param cache_root # Defines the name of the directory on the disk to contain cache files. # Default depends on the Apache version and operating system: # - Debian: /var/cache/apache2/mod_cache_disk # - FreeBSD: /var/cache/mod_cache_disk # - Red Hat, Apache 2.4: /var/cache/httpd/proxy # - Red Hat, Apache 2.2: /var/cache/mod_proxy # # @param cache_ignore_headers # Specifies HTTP header(s) that should not be stored in the cache. # # @note # Apache 2.2, mod_disk_cache installed. On Apache 2.4, mod_cache_disk installed. # # @see https://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html for additional documentation. # class apache::mod::disk_cache ( $cache_root = undef, $cache_ignore_headers = undef, - $default_cache_enable = true, + Boolean $default_cache_enable = true, ) { include apache if $cache_root { $_cache_root = $cache_root } elsif versioncmp($apache::apache_version, '2.4') >= 0 { $_cache_root = $::osfamily ? { 'debian' => '/var/cache/apache2/mod_cache_disk', 'redhat' => '/var/cache/httpd/proxy', 'freebsd' => '/var/cache/mod_cache_disk', } } else { $_cache_root = $::osfamily ? { 'debian' => '/var/cache/apache2/mod_disk_cache', 'redhat' => '/var/cache/mod_proxy', 'freebsd' => '/var/cache/mod_disk_cache', } } if versioncmp($apache::apache_version, '2.4') >= 0 { apache::mod { 'cache_disk': } } else { apache::mod { 'disk_cache': } } Class['::apache::mod::cache'] -> Class['::apache::mod::disk_cache'] # Template uses $_cache_root file { 'disk_cache.conf': ensure => file, path => "${apache::mod_dir}/disk_cache.conf", mode => $apache::file_mode, content => template('apache/mod/disk_cache.conf.erb'), require => Exec["mkdir ${apache::mod_dir}"], before => File[$apache::mod_dir], notify => Class['apache::service'], } } diff --git a/spec/classes/mod/disk_cache_spec.rb b/spec/classes/mod/disk_cache_spec.rb index f38d4f00..4242752f 100644 --- a/spec/classes/mod/disk_cache_spec.rb +++ b/spec/classes/mod/disk_cache_spec.rb @@ -1,315 +1,297 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::disk_cache', type: :class do context 'on a Debian OS' do include_examples 'Debian 8' let(:params) do { cache_ignore_headers: 'Set-Cookie', } end context 'with Apache version < 2.4' do let :pre_condition do 'class{ "apache": apache_version => "2.2", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_apache__mod('disk_cache') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/apache2\/mod_disk_cache\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } end context 'with Apache version >= 2.4' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } end context 'with $default_cache_enable = false' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => false } } it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } - it { is_expected.to contain_apache_mod('cache_disk') } + it { is_expected.to contain_apache__mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end context 'with $default_cache_enable = true' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => true } } it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } - it { is_expected.to contain_apache_mod('cache_disk') } + it { is_expected.to contain_apache__mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end context 'with $default_cache_enable = foo' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => 'foo' } } - it { is_expected.to compile } - it { is_expected.to contain_class('apache::mod::disk_cache') } - it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } - it { is_expected.to contain_apache_mod('cache_disk') } - it { - is_expected.to raise_error(Puppet::Error, 'default_cache_enable must be true or false') - } + it { is_expected.not_to compile } end end context 'on a RedHat 6-based OS' do include_examples 'RedHat 6' let(:params) do { cache_ignore_headers: 'Set-Cookie', } end context 'with Apache version < 2.4' do let :pre_condition do 'class{ "apache": apache_version => "2.2", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end it { is_expected.to contain_apache__mod('disk_cache') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_proxy\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } end context 'with Apache version >= 2.4' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end it { is_expected.to contain_apache__mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } end context 'with $default_cache_enable = false' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => false } } it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache_mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end context 'with $default_cache_enable = true' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => true } } it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache_mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end context 'with $default_cache_enable = foo' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => 'foo' } } - it { is_expected.to compile } - it { is_expected.to contain_class('apache::mod::disk_cache') } - it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } - it { is_expected.to contain_apache_mod('cache_disk') } - it { - is_expected.to raise_error(Puppet::Error, 'default_cache_enable must be true or false') - } + it { is_expected.not_to compile } end end context 'on a FreeBSD OS' do include_examples 'FreeBSD 10' let(:params) do { cache_ignore_headers: 'Set-Cookie', } end context 'with Apache version < 2.4' do let :pre_condition do 'class{ "apache": apache_version => "2.2", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('disk_cache') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_disk_cache\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } end context 'with Apache version >= 2.4' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } end context 'with $default_cache_enable = false' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => false } } it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } - it { is_expected.to contain_apache_mod('cache_disk') } + it { is_expected.to contain_apache__mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end context 'with $default_cache_enable = true' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => true } } it { is_expected.to compile } it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } - it { is_expected.to contain_apache_mod('cache_disk') } + it { is_expected.to contain_apache__mod('cache_disk') } it { is_expected.to contain_file('disk_cache.conf') .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end context 'with $default_cache_enable = foo' do let :pre_condition do 'class{ "apache": apache_version => "2.4", default_mods => ["cache"], mod_dir => "/tmp/junk", }' end let(:params) { { 'default_cache_enable' => 'foo' } } - it { is_expected.to compile } - it { is_expected.to contain_class('apache::mod::disk_cache') } - it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } - it { is_expected.to contain_apache_mod('cache_disk') } - it { - is_expected.to raise_error(Puppet::Error, 'default_cache_enable must be true or false') - } + it { is_expected.not_to compile } end end end