Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some tooling to logrotate::base to enhance flexibility #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fixtures:
repositories:
'stdlib': "git://github.com/puppetlabs/puppetlabs-stdlib.git"
symlinks:
'logrotate': "#{source_dir}"
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
22 changes: 18 additions & 4 deletions manifests/base.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
# Examples
#
# include logrotate::base
class logrotate::base {
package { 'logrotate':
ensure => latest,
class logrotate::base(
$backup = false,
$pkg_ensure = 'latest',
$pkg_name = 'logrotate',
$purge = false,
){
validate_bool($purge)
validate_bool($backup)

validate_string($pkg_ensure)
validate_string($pkg_name)

package { $pkg_name:
ensure => $pkg_ensure,
alias => 'logrotate',
}

File {
Expand All @@ -21,7 +33,9 @@
source => 'puppet:///modules/logrotate/etc/logrotate.conf';
'/etc/logrotate.d':
ensure => directory,
mode => '0755';
backup => $backup,
mode => '0755',
purge => $purge;
'/etc/cron.daily/logrotate':
ensure => file,
mode => '0555',
Expand Down
83 changes: 56 additions & 27 deletions spec/classes/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
require 'spec_helper'

describe 'logrotate::base' do
context 'input validation' do
['purge','backup'].each do |bools|
context "when #{bools} is not a boolean" do
let (:params){{bools => "BOGON"}}
it 'should fail' do
expect { subject }.to raise_error(Puppet::Error, /"BOGON" is not a boolean. It looks to be a String/)
end
end
end#bools
['pkg_ensure','pkg_name'].each do |strings|
context "when the #{strings} parameter is not a string" do
let (:params) {{strings => false }}
it 'should fail' do
expect { subject }.to raise_error(Puppet::Error, /false is not a string./)
end
end
end#strings
end
['logrotate','mylogrotate'].each do |pkg_names|
context "when pkg_name has the value of #{pkg_names}" do
['latest','present','somever==1.0*'].each do |pkg_ensure_vals|
context "when pkg_ensure has the value of #{pkg_ensure_vals}" do
let (:params) {{'pkg_ensure' => pkg_ensure_vals,'pkg_name' => pkg_names}}
it {should contain_package(pkg_names).with_ensure(pkg_ensure_vals).with_alias('logrotate')}
end
end
end
end
['purge','backup'].each do |booltest|
[true,false].each do |boolval|
context "when #{booltest} is #{boolval}" do
let (:params){{booltest => boolval }}
it {should contain_file('/etc/logrotate.d').with({
'ensure' => 'directory',
'owner' => 'root',
'group' => 'root',
'mode' => '0755',
booltest => boolval,
'require' => 'Package[logrotate]',
})}
end
end
end
it do
should contain_package('logrotate').with_ensure('latest')

should contain_file('/etc/logrotate.conf').with({
'ensure' => 'file',
'owner' => 'root',
Expand All @@ -13,13 +54,6 @@
'require' => 'Package[logrotate]',
})

should contain_file('/etc/logrotate.d').with({
'ensure' => 'directory',
'owner' => 'root',
'group' => 'root',
'mode' => '0755',
'require' => 'Package[logrotate]',
})

should contain_file('/etc/cron.daily/logrotate').with({
'ensure' => 'file',
Expand All @@ -30,25 +64,20 @@
'require' => 'Package[logrotate]',
})
end

context 'on Debian' do
let(:facts) { {:osfamily => 'Debian'} }

it { should contain_class('logrotate::defaults::debian') }
end

context 'on RedHat' do
let(:facts) { {:osfamily => 'RedHat'} }

it { should contain_class('logrotate::defaults::redhat') }
['Debian','RedHat','SuSE'].each do |osfam|
context "on #{osfam}" do
let(:facts) {{ :osfamily => osfam}}
it { should contain_class("logrotate::defaults::#{osfam.downcase}")}
['purge','backup'].each do |bools|
context "when #{bools} is not a boolean" do
let (:params){{bools => "BOGON"}}
it 'should fail' do
expect { subject }.to raise_error(Puppet::Error, /"BOGON" is not a boolean. It looks to be a String/)
end
end
end
end
end

context 'on SuSE' do
let(:facts) { {:osfamily => 'SuSE'} }

it { should contain_class('logrotate::defaults::suse') }
end

context 'on Gentoo' do
let(:facts) { {:operatingsystem => 'Gentoo'} }

Expand Down