Skip to content

Commit

Permalink
nut: add spec test
Browse files Browse the repository at this point in the history
  • Loading branch information
trustchk authored and bastelfreak committed May 20, 2018
1 parent 6197c0b commit 24b6138
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifests/plugin/nut.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$upss = { },
) {

include ::collectd
include collectd


collectd::plugin { 'nut':
Expand Down
14 changes: 6 additions & 8 deletions manifests/plugin/nut/ups.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
$ensure = 'present',
) {

include ::collectd
include ::collectd::plugin::nut
include collectd
include collectd::plugin::nut

$conf_dir = $::collectd::plugin_conf_dir

validate_string($name)
$conf_dir = $collectd::plugin_conf_dir

file { "${conf_dir}/nut-ups-${name}.conf":
ensure => $ensure,
mode => '0640',
owner => 'root',
group => $::collectd::root_group,
mode => $collectd::config_mode,
owner => $collectd::config_owner,
group => $collectd::config_group,
content => template('collectd/plugin/nut/ups.conf.erb'),
notify => Service['collectd'],
}
Expand Down
36 changes: 36 additions & 0 deletions spec/classes/collectd_plugin_nut_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper'

describe 'collectd::plugin::nut', type: :class do
let :pre_condition do
'include ::collectd'
end
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
let :facts do
facts
end


context ':ensure => present, default params' do
it 'Will create /etc/collectd.d/10-nut.conf' do
is_expected.to contain_file('nut.load').
with(ensure: 'present',
path: '/etc/collectd.d/10-nut.conf',
content: %r{LoadPlugin nut})
end
end

context ':ensure => present, single entry' do
let :params do
{ upss: [ 'ups1@localhost' ] }
end
it 'Will create /etc/collectd.d/nut-ups-ups1@localhost.conf' do
is_expected.to contain_file('/etc/collectd.d/nut-ups-ups1@localhost.conf').
with(ensure: 'present',
path: '/etc/collectd.d/nut-ups-ups1@localhost.conf',
content: %r{UPS "ups1@localhost"})
end
end
end
end
end

0 comments on commit 24b6138

Please sign in to comment.