Skip to content

Commit

Permalink
Merge pull request #531 from Ensighten/nil_sensu_check
Browse files Browse the repository at this point in the history
Allow undef handlers and subscribers
  • Loading branch information
jaxxstorm authored Sep 17, 2016
2 parents f8763e2 + 9e75d02 commit 30036b0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
58 changes: 58 additions & 0 deletions spec/unit/sensu_check_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 30036b0

Please sign in to comment.