Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #441 from nvmlabs/FC032-notification-before
Browse files Browse the repository at this point in the history
FC032 allow the new :before timing on resource notifications in Chef >= 12.6.0
  • Loading branch information
tas50 committed Jun 2, 2016
2 parents ee634fd + 79cb5f8 commit 31c065f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
28 changes: 16 additions & 12 deletions features/032_check_for_invalid_notification_timing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ Feature: Check for invalid notification timings

Scenario Outline: Notification timings
Given a cookbook recipe with a resource that <type> <notification_timing>
When I check the cookbook
When I check the cookbook specifying <version> as the Chef version
Then the invalid notification timing warning 032 <display> be displayed
Examples:
| type | notification_timing | display |
| notifies | | should not |
| notifies | immediately | should not |
| notifies | immediate | should not |
| notifies | delayed | should not |
| notifies | imediately | should |
| subscribes | | should not |
| subscribes | immediately | should not |
| subscribes | immediate | should not |
| subscribes | delayed | should not |
| subscribes | imediately | should |
| type | notification_timing | version | display |
| notifies | | 12.6.0 | should not |
| notifies | before | 12.4.0 | should |
| notifies | before | 12.6.0 | should not |
| notifies | immediately | 12.6.0 | should not |
| notifies | immediate | 12.6.0 | should not |
| notifies | delayed | 12.6.0 | should not |
| notifies | imediately | 12.6.0 | should |
| subscribes | | 12.6.0 | should not |
| subscribes | before | 12.4.0 | should |
| subscribes | before | 12.6.0 | should not |
| subscribes | immediately | 12.6.0 | should not |
| subscribes | immediate | 12.6.0 | should not |
| subscribes | delayed | 12.6.0 | should not |
| subscribes | imediately | 12.6.0 | should |
2 changes: 1 addition & 1 deletion lib/foodcritic/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def notifications(ast)
# The target resource action.
action: notification_action(notify),

# The notification timing. Either `:immediate` or `:delayed`.
# The notification timing: `:before`, `:immediate` or `:delayed`.
timing: notification_timing(notify)
}
)
Expand Down
7 changes: 6 additions & 1 deletion lib/foodcritic/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,14 @@ def pry_bindings(ast)
rule 'FC032', 'Invalid notification timing' do
tags %w(correctness notifications)
recipe do |ast|
valid_timings = if resource_attribute?('file', 'notifies_before') then
[:delayed, :immediate, :before]
else
[:delayed, :immediate]
end
find_resources(ast).select do |resource|
notifications(resource).any? do |notification|
! [:delayed, :immediate].include? notification[:timing]
! valid_timings.include? notification[:timing]
end
end
end
Expand Down

0 comments on commit 31c065f

Please sign in to comment.