diff --git a/spec/classes/collectd_plugin_amqp_spec.rb b/spec/classes/collectd_plugin_amqp_spec.rb new file mode 100644 index 000000000..c1698ae3a --- /dev/null +++ b/spec/classes/collectd_plugin_amqp_spec.rb @@ -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{}) } + 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{}) } + 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{}) } + 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{}) } + 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 diff --git a/spec/unit/python_dir_spec.rb b/spec/unit/python_dir_spec.rb index 2a29c44b4..a7ebfb0c9 100644 --- a/spec/unit/python_dir_spec.rb +++ b/spec/unit/python_dir_spec.rb @@ -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 diff --git a/templates/plugin/amqp.conf.erb b/templates/plugin/amqp.conf.erb index f8e215bb6..73af39c01 100644 --- a/templates/plugin/amqp.conf.erb +++ b/templates/plugin/amqp.conf.erb @@ -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