Skip to content

Commit

Permalink
migrate plugin_write_graphite tests to rspec-puppet-facts
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed May 26, 2017
1 parent a5f8014 commit cfdfcdc
Showing 1 changed file with 52 additions and 66 deletions.
118 changes: 52 additions & 66 deletions spec/defines/collectd_plugin_write_graphite_spec.rb
@@ -1,81 +1,67 @@
require 'spec_helper'

describe 'collectd::plugin::write_graphite::carbon', type: :define do
let :facts do
{
osfamily: 'Debian',
id: 'root',
concat_basedir: '/dne',
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
collectd_version: '4.8.0',
operatingsystemmajrelease: '7',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end
on_supported_os.each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

context 'protocol should not be include with version < 5.4' do
let(:title) { 'graphite_udp' }
let :facts do
{
osfamily: 'RedHat',
collectd_version: '5.3',
concat_basedir: '/dne',
operatingsystemmajrelease: '7',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end
let :params do
{
protocol: 'udp'
}
end
options = os_specific_options(facts)

it 'does not include protocol in /etc/collectd.d/write_graphite.conf for collectd < 5.4' do
is_expected.not_to contain_concat__fragment(
'collectd_plugin_write_graphite_conf_localhost_2003'
).with_content(%r{.*Protocol \"udp\".*})
end
end
context 'protocol should not be include with version < 5.4' do
let(:title) { 'graphite_udp' }
let :facts do
facts.merge(collectd_version: '5.3')
end
let :params do
{
protocol: 'udp'
}
end

context 'protocol should be include with version >= 5.4' do
let(:title) { 'wg' }
let :facts do
{
osfamily: 'RedHat',
collectd_version: '5.4',
concat_basedir: '/dne',
operatingsystemmajrelease: '7',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end
let :params do
{
protocol: 'udp'
}
end
it "does not include protocol in #{options[:plugin_conf_dir]}/write_graphite.conf for collectd < 5.4" do
is_expected.not_to contain_concat__fragment('collectd_plugin_write_graphite_conf_localhost_2003').with_content(%r{.*Protocol \"udp\".*})
end
end

it 'includes protocol in /etc/collectd.d/write_graphite.conf for collectd >= 5.4' do
is_expected.to contain_concat__fragment(
'collectd_plugin_write_graphite_conf_wg_udp_2003'
).with_content(%r{.*Protocol \"udp\".*})
end
context 'protocol should be include with version >= 5.4' do
let(:title) { 'wg' }
let :facts do
facts.merge(collectd_version: '5.4')
end
end
let :params do
{
protocol: 'udp'
}
end

it 'uses Node definition' do
is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_wg_udp_2003').with(content: %r{<Node "wg">},
target: '/etc/collectd.d/write_graphite-config.conf')
end
end
it "includes protocol in #{options[:plugin_conf_dir]}/write_graphite.conf for collectd >= 5.4" do
is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_wg_udp_2003').with_content(%r{.*Protocol \"udp\".*})
end

it 'uses Node definition' do
is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_wg_udp_2003').with(
content: %r{<Node "wg">},
target: "#{options[:plugin_conf_dir]}/write_graphite-config.conf"
)
end
end

context 'default configuration (undefined collectd version)' do
let(:title) { 'graphite_default' }
context 'default configuration (undefined collectd version)' do
let(:title) { 'graphite_default' }

it 'includes carbon configuration' do
is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_graphite_default_tcp_2003').with(content: %r{<Carbon>},
target: '/etc/collectd/conf.d/write_graphite-config.conf')
it 'includes carbon configuration' do
is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_graphite_default_tcp_2003').with(
content: %r{<Carbon>},
target: "#{options[:plugin_conf_dir]}/write_graphite-config.conf"
)

is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_graphite_default_tcp_2003').with(content: %r{Host "localhost"})
is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_graphite_default_tcp_2003').with(content: %r{Host "localhost"})

is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_graphite_default_tcp_2003').with(content: %r{Port "2003"})
is_expected.to contain_concat__fragment('collectd_plugin_write_graphite_conf_graphite_default_tcp_2003').with(content: %r{Port "2003"})
end
end
end
end

0 comments on commit cfdfcdc

Please sign in to comment.