Skip to content

Commit

Permalink
Updated rspec tests to deal with fix to template.
Browse files Browse the repository at this point in the history
Added shell_config to .fixtures.yml.
Added a whole lot of testing of various parameters and template
configurations on all supported osfamilies.
  • Loading branch information
razorsedge authored and Joshua Hoblitt committed Aug 4, 2013
1 parent ecd8877 commit 9b35dd8
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fixtures:
repositories:
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
# "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
"shell_config": "http://tig.csail.mit.edu/git-public/shell_config.git/"
symlinks:
"smartd": "#{source_dir}"

215 changes: 214 additions & 1 deletion spec/classes/smartd_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,219 @@
require 'spec_helper'

describe 'smartd' do
describe 'smartd', :type => 'class' do

context 'on a non-supported osfamily' do
let(:params) {{}}
let(:facts) {{ :osfamily => 'foo' }}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /smartd: unsupported OS family bar/)
}
end
end

context 'on a supported osfamily, default parameters' do
describe 'for osfamily RedHat' do
let(:params) {{}}
let(:facts) {{ :osfamily => 'RedHat' }}
it { should contain_package('smartmontools').with_ensure('present') }
it { should contain_service('smartd').with(
:ensure => 'running',
:enable => true,
:hasrestart => true
)}
it { should contain_file('/etc/smartd.conf').with(
:ensure => 'present',
:owner => 'root',
:group => '0',
:mode => '0644',
:require => 'Package[smartmontools]',
:before => 'Service[smartd]',
:notify => 'Service[smartd]'
)}
it 'should contain File[/etc/smartd.conf] with correct contents' do
verify_contents(subject, '/etc/smartd.conf', [
'DEFAULT -m root -M daily',
'DEVICESCAN',
])
end
it { should_not contain_shell_config('start_smartd') }
end

describe 'for osfamily Debian' do
let(:params) {{}}
let(:facts) {{ :osfamily => 'Debian' }}
it { should contain_package('smartmontools').with_ensure('present') }
it { should contain_service('smartd').with(
:ensure => 'running',
:enable => true,
:hasrestart => true
)}
it { should contain_file('/etc/smartd.conf').with(
:ensure => 'present',
:owner => 'root',
:group => '0',
:mode => '0644',
:require => 'Package[smartmontools]',
:before => 'Service[smartd]',
:notify => 'Service[smartd]'
)}
it 'should contain File[/etc/smartd.conf] with correct contents' do
verify_contents(subject, '/etc/smartd.conf', [
'DEFAULT -m root -M daily',
'DEVICESCAN',
])
end
it { should contain_shell_config('start_smartd').with(
:ensure => 'present',
:file => '/etc/default/smartmontools',
:key => 'start_smartd',
:value => 'yes',
:before => 'Service[smartd]'
)}
end

describe 'for osfamily FreeBSD' do
let(:params) {{}}
let(:facts) {{ :osfamily => 'FreeBSD' }}
it { should contain_package('smartmontools').with_ensure('present') }
it { should contain_service('smartd').with(
:ensure => 'running',
:enable => true,
:hasrestart => true
)}
it { should contain_file('/usr/local/etc/smartd.conf').with(
:ensure => 'present',
:owner => 'root',
:group => '0',
:mode => '0644',
:require => 'Package[smartmontools]',
:before => 'Service[smartd]',
:notify => 'Service[smartd]'
)}
it 'should contain File[/usr/local/etc/smartd.conf] with correct contents' do
verify_contents(subject, '/usr/local/etc/smartd.conf', [
'DEFAULT -m root -M daily',
'DEVICESCAN',
])
end
it { should_not contain_shell_config('start_smartd') }
end

end

context 'on a supported osfamily, custom parameters' do
let(:facts) {{ :osfamily => 'RedHat' }}

describe 'ensure => absent' do
let(:params) {{ :ensure => 'absent' }}
it { should contain_package('smartmontools').with_ensure('absent') }
it { should contain_service('smartd').with_ensure('stopped').with_enable(false) }
it { should contain_file('/etc/smartd.conf').with_ensure('absent') }
end

describe 'ensure => badvalue' do
let(:params) {{ :ensure => 'badvalue' }}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /unsupported value of $ensure: badvalue/)
}
end
end

describe 'autoupdate => true' do
let(:params) {{ :autoupdate => true }}
it { should contain_package('smartmontools').with_ensure('latest') }
it { should contain_service('smartd').with_ensure('running').with_enable(true) }
it { should contain_file('/etc/smartd.conf').with_ensure('present') }
end

describe 'autoupdate => badvalue' do
let(:params) {{ :autoupdate => 'badvalue' }}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /"badvalue" is not a boolean./)
}
end
end

describe 'devicescan => false' do
let(:params) {{ :devicescan => false }}
it { should contain_file('/etc/smartd.conf').with_ensure('present') }
it { should_not contain_file('/etc/smartd.conf').with_content(/^DEVICESCAN$/) }
end

describe 'devicescan_options => somevalue' do
let(:params) {{ :devicescan_options => 'somevalue' }}
it { should contain_file('/etc/smartd.conf').with_ensure('present') }
it 'should contain File[/etc/smartd.conf] with contents "DEVICESCAN somevalue"' do
verify_contents(subject, '/etc/smartd.conf', [
'DEFAULT -m root -M daily',
'DEVICESCAN somevalue',
])
end
end

describe 'devices => [ /dev/sg1, /dev/sg2 ]' do
let(:params) {{ :devices => [ '/dev/sg1', '/dev/sg2', ] }}
it { should contain_file('/etc/smartd.conf').with_ensure('present') }
it 'should contain File[/etc/smartd.conf] with contents "/dev/sg1\n/dev/sg2"' do
verify_contents(subject, '/etc/smartd.conf', [
'DEFAULT -m root -M daily',
'/dev/sg1',
'/dev/sg2',
])
end
end

describe 'device_opts => "{ /dev/sg1 => -o on -S on -a, /dev/sg2 => -o on -S on -a }"' do
let :params do {
:devices => [ '/dev/sg1', '/dev/sg2', ],
:device_opts => { '/dev/sg1' => '-o on -S on -a', '/dev/sg2' => '-o on -S on -a' }
}
end
it { should contain_file('/etc/smartd.conf').with_ensure('present') }
it 'should contain File[/etc/smartd.conf] with contents "/dev/sg1 -o on -S on -a\n/dev/sg2 -o on -S on -a"' do
verify_contents(subject, '/etc/smartd.conf', [
'DEFAULT -m root -M daily',
'/dev/sg1 -o on -S on -a',
'/dev/sg2 -o on -S on -a',
])
end
end

describe 'mail_to => someguy@localdomain' do
let(:params) {{ :mail_to => 'someguy@localdomain' }}
it { should contain_file('/etc/smartd.conf').with_ensure('present') }
it 'should contain File[/etc/smartd.conf] with contents "DEFAULT -m someguy@localdomain -M daily"' do
verify_contents(subject, '/etc/smartd.conf', [
'DEFAULT -m someguy@localdomain -M daily',
])
end
end

describe 'warning_schedule => diminishing' do
let(:params) {{ :warning_schedule => 'diminishing' }}
it { should contain_file('/etc/smartd.conf').with_ensure('present') }
it 'should contain File[/etc/smartd.conf] with contents "DEFAULT -m root -M diminishing"' do
verify_contents(subject, '/etc/smartd.conf', [
'DEFAULT -m root -M diminishing',
])
end
end

describe 'warning_schedule => badvalue' do
let(:params) {{ :warning_schedule => 'badvalue' }}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /$warning_schedule must be either daily, once, or diminishing./)
}
end
end

end


let(:title) { 'redhat' }
let(:facts) { {:osfamily=> 'RedHat', :lsbmajordistrelease => 6} }

Expand Down

0 comments on commit 9b35dd8

Please sign in to comment.