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

Commit

Permalink
FC003: Don't ignore solo checks with or, refs #103
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Crump committed Mar 19, 2013
1 parent 99bc679 commit 9a28569
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions features/003_check_for_chef_server.feature
Expand Up @@ -40,3 +40,8 @@ Feature: Check for Chef Server
Given a cookbook with a single recipe that searches but checks first (method) to see if this is server
When I check the cookbook
Then the check for server warning 003 should not be displayed given we have checked

Scenario: Search checking for server (alternation)
Given a cookbook with a single recipe that searches but checks first (alternation) to see if this is server
When I check the cookbook
Then the check for server warning 003 should not be displayed against the condition
15 changes: 15 additions & 0 deletions features/step_definitions/cookbook_steps.rb
Expand Up @@ -1044,6 +1044,17 @@ def in_tier?(*tier)
'a literal and interpolated variable' => :literal_and_interpolated_symbol}[path_type])
end

Given 'a cookbook with a single recipe that searches but checks first (alternation) to see if this is server' do
write_recipe %q{
if Chef::Config[:solo] || we_dont_want_to_use_search
# set up stuff from attributes
else
# set up stuff from search
nodes = search(:node, "hostname:[* TO *] AND chef_environment:#{node.chef_environment}")
end
}
end

Given /^a cookbook with a single recipe that searches but checks first( \(string\))? to see if this is server$/ do |str|
write_recipe %Q{
if Chef::Config[#{str ? "'solo'" : ":solo"}]
Expand Down Expand Up @@ -1465,6 +1476,10 @@ def search(bag_name, query=nil, sort=nil, start=0, rows=1000, &block)
assert_build_result(build_outcome == 'succeed', warnings.gsub(' ', '').split(','))
end

Then 'the check for server warning 003 should not be displayed against the condition' do
expect_warning("FC003", :line => 5, :expect_warning => false)
end

Then 'the check for server warning 003 should not be displayed given we have checked' do
expect_warning("FC003", :line => 4, :expect_warning => false)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/foodcritic/api.rb
Expand Up @@ -34,10 +34,10 @@ def attribute_access(ast, options = {})
# Does the specified recipe check for Chef Solo?
def checks_for_chef_solo?(ast)
raise_unless_xpath!(ast)

# TODO: This expression is too loose, but also will fail to match other
# types of conditionals.
! ast.xpath(%q{//*[self::if or self::unless]/*[self::aref or self::call]
! ast.xpath(%q{//*[self::if or self::unless]/*[self::aref or
child::aref or self::call]
[count(descendant::const[@value = 'Chef' or @value = 'Config']) = 2
and
( count(descendant::ident[@value='solo']) > 0
Expand Down

0 comments on commit 9a28569

Please sign in to comment.