|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'collectd::plugin::snmp::host', :type => :define do |
| 4 | + let :facts do |
| 5 | + {:osfamily => 'Debian'} |
| 6 | + end |
| 7 | + |
| 8 | + let (:title) { 'foo.example.com' } |
| 9 | + let (:required_params) {{ |
| 10 | + :collect => 'foo' |
| 11 | + }} |
| 12 | + |
| 13 | + let (:filename) { 'snmp-host-foo.example.com.conf' } |
| 14 | + |
| 15 | + context 'default params' do |
| 16 | + let (:params) { required_params } |
| 17 | + |
| 18 | + it { should contain_file(filename).with( |
| 19 | + :ensure => 'present', |
| 20 | + :path => '/etc/collectd/conf.d/25-snmp-host-foo.example.com.conf' |
| 21 | + ) } |
| 22 | + |
| 23 | + it { should contain_file(filename).that_notifies('Service[collectd]') } |
| 24 | + it { should contain_file(filename).with_content(/<Plugin snmp>/) } |
| 25 | + it { should contain_file(filename).with_content(/<Host "foo\.example\.com">/) } |
| 26 | + it { should contain_file(filename).with_content(/Address "foo\.example\.com"/) } |
| 27 | + it { should contain_file(filename).with_content(/Version 1/) } |
| 28 | + it { should contain_file(filename).with_content(/Community "public"/) } |
| 29 | + it { should contain_file(filename).without_content(/Interval \d+/) } |
| 30 | + end |
| 31 | + |
| 32 | + context 'all params set' do |
| 33 | + let (:params) { |
| 34 | + required_params.merge({ |
| 35 | + :address => 'bar.example.com', |
| 36 | + :version => '2', |
| 37 | + :community => 'opensesame', |
| 38 | + :interval => '30', |
| 39 | + }) |
| 40 | + } |
| 41 | + it { should contain_file(filename).with_content(/Address "bar\.example\.com"/) } |
| 42 | + it { should contain_file(filename).with_content(/Version 2/) } |
| 43 | + it { should contain_file(filename).with_content(/Community "opensesame"/) } |
| 44 | + it { should contain_file(filename).with_content(/Interval 30/) } |
| 45 | + end |
| 46 | + |
| 47 | + context 'collect is an array' do |
| 48 | + let (:params) {{ |
| 49 | + :collect => %w{ foo bar baz } |
| 50 | + }} |
| 51 | + it { should contain_file(filename).with_content(/Collect foo bar baz/) } |
| 52 | + end |
| 53 | + |
| 54 | + context 'collect is just a string' do |
| 55 | + let (:params) {{ |
| 56 | + :collect => 'bat' |
| 57 | + }} |
| 58 | + it { should contain_file(filename).with_content(/Collect bat/) } |
| 59 | + end |
| 60 | +end |
0 commit comments