Permalink
Browse files

FC037: Invalid notification action.

  • Loading branch information...
1 parent 6ad8397 commit d84c0954f9c62e0a298e34cb48d6b65468a2132a @acrmp committed Aug 8, 2012
View
22 features/037_check_for_invalid_notification_action.feature
@@ -0,0 +1,22 @@
+Feature: Check for invalid notification actions
+
+ In order to flag invalid notifications more quickly
+ As a developer
+ I want to identify notifications that have an action which is invalid for the notified resource
+
+ Scenario Outline: Notification actions
+ Given a cookbook recipe with a resource that <type> a <resource> to <action>
+ When I check the cookbook
+ Then the invalid notification action warning 037 <display> be displayed
+ Examples:
+ | type | resource | action | display |
+ | notifies | service | restart | should not |
+ | notifies | service | nothing | should not |
+ | notifies | service | create | should |
+ | notifies | execute | run | should not |
+ | notifies | execute | execute | should |
+ | subscribes | service | restart | should not |
+ | subscribes | service | nothing | should not |
+ | subscribes | service | create | should |
+ | subscribes | execute | run | should not |
+ | subscribes | execute | execute | should |
View
12 features/step_definitions/cookbook_steps.rb
@@ -394,6 +394,18 @@
}
end
+Given /^a cookbook recipe with a resource that (notifies|subscribes) a ([^ ]+) to ([^ ]+)$/ do |type, resource, action|
+ notification = case type
+ when 'notifies' then %Q{notifies :#{action}, "#{resource}[foo]"}
+ when 'subscribes' then %Q{subscribes :#{action}, resources(:#{resource} => "foo")}
+ end
+ write_recipe %Q{
+ template "/etc/apache.conf" do
+ #{notification}
+ end
+ }
+end
+
Given 'a cookbook recipe with a resource that notifies where the name contains a sub-expression' do
write_recipe %q{
template "/etc/apache.conf" do
View
1 features/support/command_helpers.rb
@@ -42,6 +42,7 @@ module CommandHelpers
'FC034' => 'Unused template variables',
'FC035' => 'Template uses node attribute directly',
'FC036' => 'Notified or subscribed resource does not exist',
+ 'FC037' => 'Invalid notification action',
'FCTEST001' => 'Test Rule'
}
View
11 lib/foodcritic/rules.rb
@@ -488,3 +488,14 @@
end.map{|r| {:filename => r[:filename]}.merge(match(r[:ast]))}
end
end
+
+rule "FC037", "Invalid notification action" do
+ tags %w{correctness}
+ recipe do |ast|
+ find_resources(ast).select do |resource|
+ notifications(resource).any? do |n|
+ ! resource_action?(n[:resource_type], n[:action])
+ end
+ end
+ end
+end

0 comments on commit d84c095

Please sign in to comment.