diff options
author | Matt Veitas <mveitas@gmail.com> | 2014-03-09 16:25:58 -0400 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-03-28 16:16:47 -0700 |
commit | 6aff6124ccb37e267e1fa6ca68a2ad96f1bb63c0 (patch) | |
tree | b2a724c9c18665660c48437cfb1cfd5d84199ca9 | |
parent | 349a0ddab572720bb856afb27112670144c1de05 (diff) | |
download | chef-6aff6124ccb37e267e1fa6ca68a2ad96f1bb63c0.tar.gz |
CHEF-4203: Honor the chefignore file for knife cookbook test
In the case that a standalone cookbook exists that is using bundler, a large amount of gems can be added to the current directory. This commit reads the chefignore file and avoid having to scan through the ruby files that are in the bundler created gems directory.
-rw-r--r-- | lib/chef/cookbook/chefignore.rb | 12 | ||||
-rw-r--r-- | lib/chef/cookbook/syntax_check.rb | 10 | ||||
-rw-r--r-- | spec/data/standalone_cookbook/Gemfile | 1 | ||||
-rw-r--r-- | spec/data/standalone_cookbook/chefignore | 9 | ||||
-rw-r--r-- | spec/data/standalone_cookbook/recipes/default.rb | 3 | ||||
-rw-r--r-- | spec/data/standalone_cookbook/vendor/bundle/ruby/2.0.0/gems/multi_json-1.9.0/lib/multi_json.rb | 1 | ||||
-rw-r--r-- | spec/unit/cookbook/chefignore_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/cookbook/syntax_check_spec.rb | 17 |
8 files changed, 55 insertions, 8 deletions
diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb index 17c000350d..efeaf0cb67 100644 --- a/lib/chef/cookbook/chefignore.rb +++ b/lib/chef/cookbook/chefignore.rb @@ -25,7 +25,11 @@ class Chef attr_reader :ignores def initialize(ignore_file_or_repo) + # Check the 'ignore_file_or_repo' path first and then look in the parent directory + # to handle both the chef repo cookbook layout and a standalone cookbook @ignore_file = find_ignore_file(ignore_file_or_repo) + @ignore_file = find_ignore_file(File.dirname(ignore_file_or_repo)) unless exists?(@ignore_file) + @ignores = parse_ignore_file end @@ -43,8 +47,7 @@ class Chef def parse_ignore_file ignore_globs = [] - if File.exist?(@ignore_file) && File.readable?(@ignore_file) && - (File.file?(@ignore_file) || File.symlink?(@ignore_file)) + if exists?(@ignore_file) File.foreach(@ignore_file) do |line| ignore_globs << line.strip unless line =~ COMMENTS_AND_WHITESPACE end @@ -61,6 +64,11 @@ class Chef File.join(path, 'chefignore') end end + + def exists?(path) + File.exist?(@ignore_file) && File.readable?(@ignore_file) && + (File.file?(@ignore_file) || File.symlink?(@ignore_file)) + end end end end diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb index 4f8dcff6dc..0f0fe3255b 100644 --- a/lib/chef/cookbook/syntax_check.rb +++ b/lib/chef/cookbook/syntax_check.rb @@ -92,20 +92,18 @@ class Chef # cookbook_path::: the (on disk) path to the cookbook def initialize(cookbook_path) @cookbook_path = cookbook_path - @validated_files = PersistentSet.new - end + @chefignore ||= Chefignore.new(cookbook_path) - def chefignore - @chefignore ||= Chefignore.new(File.dirname(cookbook_path)) + @validated_files = PersistentSet.new end def remove_ignored_files(file_list) - return file_list unless chefignore.ignores.length > 0 + return file_list unless @chefignore.ignores.length > 0 file_list.reject do |full_path| cookbook_pn = Pathname.new cookbook_path full_pn = Pathname.new full_path relative_pn = full_pn.relative_path_from cookbook_pn - chefignore.ignored? relative_pn.to_s + @chefignore.ignored? relative_pn.to_s end end diff --git a/spec/data/standalone_cookbook/Gemfile b/spec/data/standalone_cookbook/Gemfile new file mode 100644 index 0000000000..9c961848d8 --- /dev/null +++ b/spec/data/standalone_cookbook/Gemfile @@ -0,0 +1 @@ +source "https://rubygems.org/"
\ No newline at end of file diff --git a/spec/data/standalone_cookbook/chefignore b/spec/data/standalone_cookbook/chefignore new file mode 100644 index 0000000000..cd18e699c1 --- /dev/null +++ b/spec/data/standalone_cookbook/chefignore @@ -0,0 +1,9 @@ +# +# The ignore file allows you to skip files in cookbooks with the same name that appear +# later in the search path. +# + +recipes/ignoreme.rb + # comments can be indented +ignored +vendor/bundle/* diff --git a/spec/data/standalone_cookbook/recipes/default.rb b/spec/data/standalone_cookbook/recipes/default.rb new file mode 100644 index 0000000000..c2fa53be32 --- /dev/null +++ b/spec/data/standalone_cookbook/recipes/default.rb @@ -0,0 +1,3 @@ +# +# Nothing ot see here +#
\ No newline at end of file diff --git a/spec/data/standalone_cookbook/vendor/bundle/ruby/2.0.0/gems/multi_json-1.9.0/lib/multi_json.rb b/spec/data/standalone_cookbook/vendor/bundle/ruby/2.0.0/gems/multi_json-1.9.0/lib/multi_json.rb new file mode 100644 index 0000000000..3b992add1a --- /dev/null +++ b/spec/data/standalone_cookbook/vendor/bundle/ruby/2.0.0/gems/multi_json-1.9.0/lib/multi_json.rb @@ -0,0 +1 @@ +# This is a dummy ruby file
\ No newline at end of file diff --git a/spec/unit/cookbook/chefignore_spec.rb b/spec/unit/cookbook/chefignore_spec.rb index aacb60c012..e529a6d05a 100644 --- a/spec/unit/cookbook/chefignore_spec.rb +++ b/spec/unit/cookbook/chefignore_spec.rb @@ -36,4 +36,14 @@ describe Chef::Cookbook::Chefignore do @chefignore.ignored?('recipes/ignoreme.rb').should be_true @chefignore.ignored?('recipes/dontignoreme.rb').should be_false end + + context "when using the single cookbook pattern" do + before do + @chefignore = Chef::Cookbook::Chefignore.new(File.join(CHEF_SPEC_DATA, 'standalone_cookbook')) + end + + it "loads the globs in the chefignore file" do + @chefignore.ignores.should =~ %w[recipes/ignoreme.rb ignored vendor/bundle/*] + end + end end diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb index 40a89c99a4..190a7e1936 100644 --- a/spec/unit/cookbook/syntax_check_spec.rb +++ b/spec/unit/cookbook/syntax_check_spec.rb @@ -47,6 +47,23 @@ describe Chef::Cookbook::SyntaxCheck do Chef::Config[:cookbook_path] = File.dirname(cookbook_path) syntax_check = Chef::Cookbook::SyntaxCheck.for_cookbook(:openldap) syntax_check.cookbook_path.should == cookbook_path + syntax_check.ruby_files.length.should == 8 + end + + it "creates a syntax checker given the cookbook name and cookbook_path" do + syntax_check = Chef::Cookbook::SyntaxCheck.for_cookbook(:openldap, File.join(CHEF_SPEC_DATA, 'cookbooks')) + syntax_check.cookbook_path.should == cookbook_path + syntax_check.ruby_files.length.should == 8 + end + + context "when using a standalone cookbook" do + let(:cookbook_path) { File.join(CHEF_SPEC_DATA, 'standalone_cookbook') } + + it "creates a syntax checker given the cookbook name and cookbook_path for a standalone cookbook" do + syntax_check = Chef::Cookbook::SyntaxCheck.for_cookbook(:standalone_cookbook, CHEF_SPEC_DATA) + syntax_check.cookbook_path.should == cookbook_path + syntax_check.ruby_files.length.should == 1 + end end describe "when first created" do |