Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for the AMQP plugin and fix broken StoreRates configuration when amqpformat = JSON #661

Merged
merged 3 commits into from
Apr 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions spec/classes/collectd_plugin_amqp_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require 'spec_helper'

describe 'collectd::plugin::amqp', type: :class do
on_supported_os.each do |os, facts|
context "on #{os} " do
let :facts do
facts
end
options = os_specific_options(facts)
context ':ensure => present' do
let :params do
{ ensure: 'present' }
end
it { is_expected.to contain_collectd__plugin('amqp') }
it { is_expected.to contain_file('old_amqp.load').with_ensure('absent') }
it { is_expected.to contain_file('older_amqp.load').with_ensure('absent') }
it 'Will create 10-amqp.conf' do
is_expected.to contain_file('amqp.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-amqp.conf"
)
end
it { is_expected.to contain_file('amqp.load').with(content: %r{<Publish "graphite">}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Host "localhost"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Port "5672"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{VHost "graphite"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{User "graphite"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Password "graphite"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Format "Graphite"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{StoreRates false}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Exchange "metrics"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Persistent true}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphitePrefix "collectd."}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphiteEscapeChar "_"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{</Publish>}) }
end
context 'overriding default parameters' do
let(:params) do
{ amqphost: 'myhost',
amqpport: '5666',
amqpvhost: 'amqp',
amqpuser: 'user',
amqppass: 'pass',
amqpformat: 'JSON',
amqpstorerates: true,
amqpexchange: 'ex',
amqppersistent: false,
graphiteprefix: 'prefix',
escapecharacter: '|',
graphiteseparateinstances: true,
graphitealwaysappendds: true }
end
it { is_expected.to contain_file('amqp.load').with(content: %r{<Publish "graphite">}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Host "myhost"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Port "5666"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{VHost "amqp"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{User "user"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Password "pass"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Format "JSON"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{StoreRates true}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Exchange "ex"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Persistent false}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphitePrefix "prefix"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphiteEscapeChar "\|"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{</Publish>}) }
context 'with collectd 5.5+' do
let :facts do
facts.merge(collectd_version: '5.6.0')
end
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphiteSeparateInstances true}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphiteAlwaysAppendDS true}) }
end
end

context ':ensure => absent' do
let :params do
{ ensure: 'absent' }
end
it 'Will not create 10-amqp.conf' do
is_expected.to contain_file('amqp.load').with(
ensure: 'absent',
path: "#{options[:plugin_conf_dir]}/10-amqp.conf"
)
end
end
end
end
end
2 changes: 2 additions & 0 deletions spec/unit/python_dir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
describe 'python dir' do
context 'default path' do
before do
# This is needed to make this spec work on Fedora, apparently
Facter.fact(:osfamily).stubs(:value).returns('AnythingNotRedHat')
Facter::Util::Resolution.stubs(:which).with('python').returns(true)
Facter::Util::Resolution.stubs(:exec).with('python -c "import site; print(site.getsitepackages()[0])"').returns('/usr/local/lib/python2.7/dist-packages')
end
Expand Down
2 changes: 1 addition & 1 deletion templates/plugin/amqp.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
User "<%= @amqpuser %>"
Password "<%= @amqppass %>"
Format "<%= @amqpformat %>"
<% if @amqpstorerates and @amqformat == 'JSON' -%>
<% if @amqpstorerates and @amqpformat == 'JSON' -%>
StoreRates true
<% else -%>
StoreRates false
Expand Down