Skip to content

Commit

Permalink
Merge pull request #538 from cwjohnston/fix/allow-delete-without-vali…
Browse files Browse the repository at this point in the history
…dation

[sensu_check] validate subscribers/standalone on create action only
  • Loading branch information
amdprophet authored Mar 9, 2017
2 parents 9ffe2dc + 70f2d62 commit 9a942f1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion resources/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ def after_created
raise Chef::Exceptions::ValidationFailed, "Sensu check #{name}: name cannot contain spaces or special characters"
end

raise Chef::Exceptions::ValidationFailed, "Sensu check #{name}: must either define subscribers, or has to be standalone." unless (subscribers || standalone)
if action == :create
raise Chef::Exceptions::ValidationFailed, "Sensu check #{name}: must either define subscribers, or has to be standalone." unless (subscribers || standalone)
end
end
5 changes: 4 additions & 1 deletion test/cookbooks/sensu-test/recipes/good_checks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

sensu_check "valid_standalone_check" do
interval 20
command 'true'
Expand All @@ -10,3 +9,7 @@
command 'true'
subscribers ['all']
end

sensu_check "removed_check" do
action :delete
end
7 changes: 7 additions & 0 deletions test/unit/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
expect(chef_run).to create_sensu_check("valid_pubsub_check").with(:subscribers => ['all'])
end

it "deletes removed_check without specifying subscriptions/standalone" do
expect(chef_run).to delete_sensu_check("removed_check").with(
:subscribers => nil,
:standalone => nil
)
end

end

describe 'sensu-test::bad_check_name' do
Expand Down

0 comments on commit 9a942f1

Please sign in to comment.