diff --git a/lib/puppet/type/sensu_check.rb b/lib/puppet/type/sensu_check.rb index 2bfed73de3..c495949e1b 100644 --- a/lib/puppet/type/sensu_check.rb +++ b/lib/puppet/type/sensu_check.rb @@ -45,7 +45,8 @@ def insync?(is) newproperty(:handlers, :array_matching => :all) do desc "List of handlers that responds to this check" def insync?(is) - is.sort == should.sort + return is.sort == should.sort if is.is_a?(Array) && should.is_a?(Array) + is == should end end @@ -81,7 +82,8 @@ def insync?(is) newproperty(:subscribers, :array_matching => :all) do desc "Who is subscribed to this check" def insync?(is) - is.sort == should.sort + return is.sort == should.sort if is.is_a?(Array) && should.is_a?(Array) + is == should end end diff --git a/spec/unit/sensu_check_spec.rb b/spec/unit/sensu_check_spec.rb new file mode 100644 index 0000000000..5b0b1333b2 --- /dev/null +++ b/spec/unit/sensu_check_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe Puppet::Type.type(:sensu_check) do + let(:resource_hash) do + { + :title => 'foo.example.com', + :catalog => Puppet::Resource::Catalog.new + } + end + + describe 'handlers' do + it 'should support a string as a value' do + expect( + described_class.new(resource_hash.merge(:handlers => 'default'))[:handlers] + ).to eq ['default'] + end + + it 'should support an array as a value' do + expect( + described_class.new( + resource_hash.merge(:handlers => %w(handler1 handler2)) + )[:handlers] + ).to eq %w(handler1 handler2) + end + + # it 'should support nil as a value' do + # expect( + # described_class.new( + # resource_hash.merge(:handlers => nil) + # )[:handlers] + # ).to eq nil + # end + end + + describe 'subscribers' do + it 'should support a string as a value' do + expect( + described_class.new(resource_hash.merge(:subscribers => 'default'))[:subscribers] + ).to eq ['default'] + end + + it 'should support an array as a value' do + expect( + described_class.new( + resource_hash.merge(:subscribers => %w(subscriber1 subscriber2)) + )[:subscribers] + ).to eq %w(subscriber1 subscriber2) + end + + # it 'should support nil as a value' do + # expect( + # described_class.new( + # resource_hash.merge(:subscribers => nil) + # )[:subscribers] + # ).to eq nil + # end + end +end