Skip to content

Commit

Permalink
Repair tests
Browse files Browse the repository at this point in the history
Fix the tests by adding some lines which got lost during the merge.
Also do not test the error messages when a wrong type is used but only
test if there is an error.
  • Loading branch information
Martin Merfort committed Jul 21, 2017
1 parent 4f755b8 commit 13ce41d
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 147 deletions.
2 changes: 2 additions & 0 deletions manifests/conf.pp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@

include ::logrotate

$rules_configdir = $::logrotate::rules_configdir

file { $path:
ensure => $ensure,
owner => $logrotate::root_user,
Expand Down
5 changes: 4 additions & 1 deletion manifests/defaults.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# apply defaults
#
class logrotate::defaults ($rule_default, $rules = { }){
class logrotate::defaults (
$rules = $logrotate::params::base_rules,
$rule_default = $logrotate::params::rule_default
){

assert_private()

Expand Down
120 changes: 110 additions & 10 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
# Params class for logrotate module
#
class logrotate::params {
$cron_daily_hour = 1
$cron_daily_minute = 0
$cron_hourly_minute = 1
$logrotate_conf = "${configdir}/logrotate.conf"
$root_user = 'root'
$rules_configdir = "${configdir}/logrotate.d"
$config_file = '/etc/logrotate.conf'

case $::osfamily {
'FreeBSD': {
$configdir = '/usr/local/etc'
$root_group = 'wheel'
$logrotate_bin = '/usr/local/sbin/logrotate'
$conf_params = {}
$conf_params = {
su_group => $default_su_group,
}
$base_rules = {
'wtmp' => {
path => '/var/log/wtmp',
create_mode => '0664',
},
'btmp' => {
path => '/var/log/btmp',
create_mode => '0600',
},
}
}
'Debian': {
$default_su_group = versioncmp($::operatingsystemmajrelease, '14.00') ? {
Expand All @@ -29,6 +33,16 @@
$configdir = '/etc'
$root_group = 'root'
$logrotate_bin = '/usr/sbin/logrotate'
$base_rules = {
'wtmp' => {
path => '/var/log/wtmp',
create_mode => '0664',
},
'btmp' => {
path => '/var/log/btmp',
create_mode => '0600',
},
}
}
'Gentoo': {
$conf_params = {
Expand All @@ -41,12 +55,98 @@
$configdir = '/etc'
$root_group = 'root'
$logrotate_bin = '/usr/sbin/logrotate'
$base_rules = {
'wtmp' => {
path => '/var/log/wtmp',
missingok => false,
create_mode => '0664',
minsize => '1M',
},
'btmp' => {
path => '/var/log/btmp',
create_mode => '0600',
},
}
}
'RedHat': {
$conf_params = {
dateext => true,
compress => true,
ifempty => false,
mail => false,
olddir => false,
}
$configdir = '/etc'
$root_group = 'root'
$logrotate_bin = '/usr/sbin/logrotate'
$base_rules = {
'wtmp' => {
path => '/var/log/wtmp',
missingok => false,
create_mode => '0664',
minsize => '1M',
},
'btmp' => {
path => '/var/log/btmp',
create_mode => '0600',
},
}
}
'SuSE': {
$conf_params = {
dateext => true,
compress => true,
ifempty => false,
mail => false,
olddir => false,
}
$configdir = '/etc'
$root_group = 'root'
$logrotate_bin = '/usr/sbin/logrotate'
$base_rules = {
'wtmp' => {
path => '/var/log/wtmp',
create_mode => '0664',
missingok => false,
},
'btmp' => {
path => '/var/log/btmp',
create_mode => '0600',
create_group => 'root',
},
}
$rule_default = {
missingok => true,
rotate_every => 'monthly',
create => true,
create_owner => 'root',
create_group => 'utmp',
rotate => 99,
maxage => 365,
size => '400k',
}
}
default: {
$conf_params = { }
$configdir = '/etc'
$root_group = 'root'
$logrotate_bin = '/usr/sbin/logrotate'
$base_rules = {}
$conf_params = {}
$rule_default = {
missingok => true,
rotate_every => 'monthly',
create => true,
create_owner => 'root',
create_group => 'utmp',
rotate => 1,
}
}
}
$cron_daily_hour = 1
$cron_daily_minute = 0
$cron_hourly_minute = 1
$config_file = '/etc/logrotate.conf'
$logrotate_conf = "${configdir}/logrotate.conf"
$root_user = 'root'
$rules_configdir = "${configdir}/logrotate.d"
}
83 changes: 4 additions & 79 deletions spec/classes/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,81 +10,6 @@
is_expected.to contain_logrotate__conf('/etc/logrotate.conf')
}
end
# Gentoo is special case, and doesn't show up in support_os
# helper method despite being in metadata.json
context 'Gentoo' do
let(:facts) { { osfamily: 'Gentoo' } }

it {
is_expected.to contain_logrotate__conf('/etc/logrotate.conf').with(
'dateext' => true,
'compress' => true,
'ifempty' => false,
'mail' => false,
'olddir' => false
)
}
it {
is_expected.to contain_logrotate__rule('wtmp').with(
'path' => '/var/log/wtmp',
'missingok' => false,
'create_mode' => '0664',
'minsize' => '1M',
'rotate_every' => 'monthly',
'create' => true,
'create_owner' => 'root',
'create_group' => 'utmp',
'rotate' => 1
)
}
it {
is_expected.to contain_logrotate__rule('btmp').with(
'path' => '/var/log/btmp',
'create_mode' => '0600',
'missingok' => true,
'rotate_every' => 'monthly',
'create' => true,
'create_owner' => 'root',
'create_group' => 'utmp',
'rotate' => 1
)
}
end
context 'SuSE' do
let(:facts) { { osfamily: 'SuSE' } }

it {
is_expected.to contain_logrotate__conf('/etc/logrotate.conf')
}
it {
is_expected.to contain_logrotate__rule('wtmp').with(
'path' => '/var/log/wtmp',
'create_mode' => '0664',
'missingok' => false,
'create' => true,
'create_owner' => 'root',
'create_group' => 'utmp',
'maxage' => 365,
'rotate' => 99,
'rotate_every' => 'monthly',
'size' => '400k'
)
}
it {
is_expected.to contain_logrotate__rule('btmp').with(
'path' => '/var/log/btmp',
'create_mode' => '0600',
'create' => true,
'create_owner' => 'root',
'create_group' => 'root',
'maxage' => 365,
'missingok' => true,
'rotate' => 99,
'rotate_every' => 'monthly',
'size' => '400k'
)
}
end
on_supported_os.each do |os, facts|
context os, if: facts[:osfamily] == 'Debian' do
let(:facts) { facts }
Expand All @@ -101,7 +26,7 @@
it {
is_expected.to contain_logrotate__rule('wtmp').with(
'rotate_every' => 'monthly',
'rotate' => '1',
'rotate' => 1,
'create' => true,
'create_mode' => '0664',
'create_owner' => 'root',
Expand All @@ -112,7 +37,7 @@
it {
is_expected.to contain_logrotate__rule('btmp').with(
'rotate_every' => 'monthly',
'rotate' => '1',
'rotate' => 1,
'create' => true,
'create_mode' => '0600',
'create_owner' => 'root',
Expand Down Expand Up @@ -143,8 +68,8 @@
it {
is_expected.to contain_logrotate__rule('btmp').with(
'path' => '/var/log/btmp',
'create_mode' => '0600',
'minsize' => '1M',
# 'create_mode' => '0600',
# 'minsize' => '1M',
'create' => true,
'create_owner' => 'root',
'create_group' => 'utmp',
Expand Down
94 changes: 45 additions & 49 deletions spec/classes/hourly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,51 @@
require 'shared_examples'

describe 'logrotate::hourly' do
context 'with default values' do
let(:pre_condition) { 'class { "::logrotate": }' }

it {
is_expected.to contain_file('/etc/logrotate.d/hourly').with(
'ensure' => 'directory',
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
)
}

it {
is_expected.to contain_file('/etc/cron.hourly/logrotate').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0555',
'source' => 'puppet:///modules/logrotate/etc/cron.hourly/logrotate',
'require' => [
'File[/etc/logrotate.d/hourly]',
'Package[logrotate]'
]
)
}
end

context 'with ensure => absent' do
let(:params) { { ensure: 'absent' } }

it do
is_expected.to contain_file('/etc/cron.hourly/logrotate').with('ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0555')
end
end

context 'with ensure => absent' do
let(:params) { { ensure: 'absent' } }

it { is_expected.to contain_file('/etc/logrotate.d/hourly').with_ensure('absent') }
it { is_expected.to contain_file('/etc/cron.hourly/logrotate').with_ensure('absent') }
end

context 'with ensure => foo' do
include_context 'config file' do
let(:config_file) { '/etc/cron.hourly/logrotate' }
context 'supported operating systems' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

let(:pre_condition) { 'class { "::logrotate": }' }

context 'with default values' do
it do
is_expected.to contain_file('/etc/logrotate.d/hourly').with(
'ensure' => 'directory',
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
)
end

it do
is_expected.to contain_file('/etc/cron.hourly/logrotate').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0555'
)
end
end

context 'with ensure => absent' do
let(:params) { { ensure: 'absent' } }

it { is_expected.to contain_file('/etc/logrotate.d/hourly').with_ensure('absent') }
it { is_expected.to contain_file('/etc/cron.hourly/logrotate').with_ensure('absent') }
end

context 'with ensure => foo' do
let(:params) { { ensure: 'foo' } }

include_context 'config file' do
let(:config_file) { '/etc/cron.hourly/logrotate' }
end
it_behaves_like 'error match', 'ensure', 'Enum'
end
end
end
it_behaves_like 'error match', 'ensure', 'Enum'
end
end
Loading

0 comments on commit 13ce41d

Please sign in to comment.