From 027e74558880b532ddbd1cfeb2d02830b65ac72e Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 9 Nov 2017 15:32:32 +0100 Subject: [PATCH] Fix the tests Also adds acceptance tests for Debian 9 and simplifications in the params. --- manifests/params.pp | 33 +++---------------- spec/classes/init_spec.rb | 69 +++++++++++---------------------------- 2 files changed, 24 insertions(+), 78 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 3388c42..65f5f41 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -32,43 +32,20 @@ $package_name = 'squid3' $service_name = 'squid3' $config = '/etc/squid3/squid.conf' - $config_user = 'root' - $config_group = 'root' $access_log = 'daemon:/var/log/squid3/access.log squid' - $daemon_user = 'proxy' - $daemon_group = 'proxy' - } - /^(9.*)$/: { - $package_name = 'squid3' - $service_name = 'squid' - $config = '/etc/squid/squid.conf' - $config_user = 'root' - $config_group = 'root' - $access_log = 'daemon:/var/log/squid/access.log squid' - $daemon_user = 'proxy' - $daemon_group = 'proxy' - } - /^16\.04$/: { - $package_name = 'squid' - $service_name = 'squid' - $config = '/etc/squid/squid.conf' - $config_user = 'root' - $config_group = 'root' - $access_log = 'daemon:/var/log/squid/access.log squid' - $daemon_user = 'proxy' - $daemon_group = 'proxy' } default: { $package_name = 'squid' $service_name = 'squid' $config = '/etc/squid/squid.conf' - $config_user = 'root' - $config_group = 'squid' $access_log = 'daemon:/var/log/squid/access.log squid' - $daemon_user = 'squid' - $daemon_group = 'squid' } } + + $config_user = 'root' + $config_group = 'root' + $daemon_user = 'proxy' + $daemon_group = 'proxy' } 'FreeBSD': { $package_name = 'squid' diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 99863e3..ffaa42a 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -6,61 +6,30 @@ facts end + let(:squid_name) do + %w[jessie trusty].include?(facts[:lsbdistcodename]) ? 'squid3' : 'squid' + end + + let(:etc_dir) do + facts[:operatingsystem] == 'FreeBSD' ? '/usr/local/etc' : '/etc' + end + + let(:config_group) do + facts[:osfamily] == 'Debian' ? 'root' : 'squid' + end + context 'with defaults for all parameters' do it { is_expected.to contain_class('squid') } it { is_expected.to contain_class('squid::install') } it { is_expected.to contain_class('squid::config') } it { is_expected.to contain_class('squid::service') } - case facts[:operatingsystem] - when 'Debian' - context 'when on Debian' do - it { is_expected.to contain_package('squid3').with_ensure('present') } - it { is_expected.to contain_service('squid3').with_ensure('running') } - it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_group('root') } - it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_owner('root') } - it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid3/squid.conf') } - it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid3/access.log\s+squid$}) } - end - when 'Ubuntu' - case facts[:operatingsystemrelease] - when '14.04' - context 'when on Ubuntu 14.04' do - it { is_expected.to contain_package('squid3').with_ensure('present') } - it { is_expected.to contain_service('squid3').with_ensure('running') } - it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_group('root') } - it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_owner('root') } - it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid3/squid.conf') } - it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid3/access.log\s+squid$}) } - end - when '16.04' - context 'when on Ubuntu 16.04' do - it { is_expected.to contain_package('squid').with_ensure('present') } - it { is_expected.to contain_service('squid').with_ensure('running') } - it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('root') } - it { is_expected.to contain_concat('/etc/squid/squid.conf').with_owner('root') } - it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid/squid.conf') } - it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) } - end - end - when 'FreeBSD' - context 'when on FreeBSD' do - it { is_expected.to contain_package('squid').with_ensure('present') } - it { is_expected.to contain_service('squid').with_ensure('running') } - it { is_expected.to contain_concat('/usr/local/etc/squid/squid.conf').with_group('squid') } - it { is_expected.to contain_concat('/usr/local/etc/squid/squid.conf').with_owner('root') } - it { is_expected.to contain_concat_fragment('squid_header').with_target('/usr/local/etc/squid/squid.conf') } - it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) } - end - else - context 'when on any other supported OS' do - it { is_expected.to contain_package('squid').with_ensure('present') } - it { is_expected.to contain_service('squid').with_ensure('running') } - it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('squid') } - it { is_expected.to contain_concat('/etc/squid/squid.conf').with_owner('root') } - it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid/squid.conf') } - it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) } - end - end + + it { is_expected.to contain_package(squid_name).with_ensure('present') } + it { is_expected.to contain_service(squid_name).with_ensure('running') } + it { is_expected.to contain_concat("#{etc_dir}/#{squid_name}/squid.conf").with_group(config_group) } + it { is_expected.to contain_concat("#{etc_dir}/#{squid_name}/squid.conf").with_owner('root') } + it { is_expected.to contain_concat_fragment('squid_header').with_target("#{etc_dir}/#{squid_name}/squid.conf") } + it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/#{squid_name}/access.log\s+squid$}) } it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^cache_mem\s+256 MB$}) } it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^maximum_object_size_in_memory\s+512 KB$}) } it { is_expected.to contain_concat_fragment('squid_header').without_content(%r{^memory_cache_shared}) }