Skip to content

Commit

Permalink
add sysstat::params class and improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Aug 29, 2013
1 parent 66d1367 commit 95cb003
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 6 deletions.
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# Copyright (C) 2013 Joshua Hoblitt
#
class sysstat {
class sysstat inherits sysstat::params {
class { 'sysstat::install': } ->
class { 'sysstat::service': } ->
Class['Sysstat']
Expand Down
2 changes: 1 addition & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Copyright (C) 2013 Joshua Hoblitt
#
class sysstat::install {
package { 'sysstat':
package { $sysstat::params::sysstat_package:
ensure => present,
}
}
22 changes: 22 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Class: sysstat::params
#
# This class should be considered private.
#
# === Authors
#
# Joshua Hoblitt <[email protected]>
#
# === Copyright
#
# Copyright (C) 2013 Joshua Hoblitt
#
class sysstat::params {
case $::osfamily {
'redhat': {
$sysstat_package = 'sysstat'
}
default: {
fail("Module ${module_name} is not supported on ${::operatingsystem}")
}
}
}
19 changes: 19 additions & 0 deletions spec/classes/sysstat_install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'

describe 'sysstat::install', :type => :class do
let :pre_condition do
'include sysstat::params'
end

describe 'for osfamily RedHat' do
let :facts do
{
:osfamily => 'RedHat',
}
end

it { should include_class('sysstat::install') }
it { should contain_package('sysstat').with_ensure('present') }
end

end
28 changes: 28 additions & 0 deletions spec/classes/sysstat_params_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec_helper'

describe 'sysstat::params', :type => :class do
describe 'for osfamily RedHat' do
let :facts do
{
:osfamily => 'RedHat',
}
end

it { should include_class('sysstat::params') }
end

describe 'unsupported osfamily' do
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
}
end

it 'should fail' do
expect { should include_class('sysstat::params') }.
to raise_error(Puppet::Error, /not supported on Debian/)
end
end

end
14 changes: 14 additions & 0 deletions spec/classes/sysstat_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

describe 'sysstat::service', :type => :class do

it do
should contain_service('sysstat').with({
:hasstatus => 'false',
:hasrestart => 'true',
:enable => 'true',
})
end

end

18 changes: 14 additions & 4 deletions spec/classes/sysstat_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
require 'spec_helper'

describe 'sysstat', :type => :class do
it { should contain_class('sysstat') }
it { should contain_class('sysstat::install') }
it { should contain_package('sysstat').with_ensure('present') }
it { should contain_class('sysstat::service') }

describe 'for osfamily RedHat' do
let :facts do
{
:osfamily => 'RedHat',
}
end

it { should include_class('sysstat') }
it { should include_class('sysstat::params') }
it { should include_class('sysstat::install') }
it { should include_class('sysstat::service') }
end

end

0 comments on commit 95cb003

Please sign in to comment.