From 336497812d0ff482cec22343e491094706ed8ef6 Mon Sep 17 00:00:00 2001 From: trustchk Date: Tue, 13 Jun 2017 15:35:00 +0000 Subject: [PATCH] nut: add spec test --- manifests/plugin/nut.pp | 2 +- manifests/plugin/nut/ups.pp | 14 ++++----- spec/classes/collectd_plugin_nut_spec.rb | 37 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 spec/classes/collectd_plugin_nut_spec.rb diff --git a/manifests/plugin/nut.pp b/manifests/plugin/nut.pp index b3d1d6fab..078164a0c 100644 --- a/manifests/plugin/nut.pp +++ b/manifests/plugin/nut.pp @@ -4,7 +4,7 @@ $upss = { }, ) { - include ::collectd + include collectd collectd::plugin { 'nut': diff --git a/manifests/plugin/nut/ups.pp b/manifests/plugin/nut/ups.pp index 695f7c47e..b9d3910ad 100644 --- a/manifests/plugin/nut/ups.pp +++ b/manifests/plugin/nut/ups.pp @@ -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'], } diff --git a/spec/classes/collectd_plugin_nut_spec.rb b/spec/classes/collectd_plugin_nut_spec.rb new file mode 100644 index 000000000..5cb775a36 --- /dev/null +++ b/spec/classes/collectd_plugin_nut_spec.rb @@ -0,0 +1,37 @@ +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