summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-11-01 09:22:23 -0700
committerGitHub <noreply@github.com>2019-11-01 09:22:23 -0700
commita421bf36a23b707fd93475eb5b30d3fcd8a0a09c (patch)
treef7591564366fcd716a85b9d294ef9bbd75ec4f60 /spec
parent09a210ccc45ac4b158a919b1a3e6dd03174b0808 (diff)
parentdd682d9040da1a5f12f4f076881cf748379e9227 (diff)
downloadchef-a421bf36a23b707fd93475eb5b30d3fcd8a0a09c.tar.gz
Merge pull request #8925 from MsysTechnologiesllc/VSingh/MSYS-1109_chefignore_for_respective_cookbook_dir
Fix multiple chefignore file issues
Diffstat (limited to 'spec')
-rw-r--r--spec/data/cookbooks/starter/chefignore8
-rw-r--r--spec/data/cookbooks/starter/files/sample.txt1
-rw-r--r--spec/data/cookbooks/starter/metadata.rb2
-rw-r--r--spec/data/cookbooks/starter/recipes/default.rb4
-rw-r--r--spec/unit/cookbook/chefignore_spec.rb42
-rw-r--r--spec/unit/cookbook_loader_spec.rb2
-rw-r--r--spec/unit/cookbook_uploader_spec.rb7
7 files changed, 53 insertions, 13 deletions
diff --git a/spec/data/cookbooks/starter/chefignore b/spec/data/cookbooks/starter/chefignore
new file mode 100644
index 0000000000..b9d6c768c2
--- /dev/null
+++ b/spec/data/cookbooks/starter/chefignore
@@ -0,0 +1,8 @@
+#
+# The ignore file allows you to skip files in cookbooks with the same name that appear
+# later in the search path.
+#
+
+recipes/default.rb
+ # comments can be indented
+ignored
diff --git a/spec/data/cookbooks/starter/files/sample.txt b/spec/data/cookbooks/starter/files/sample.txt
new file mode 100644
index 0000000000..e635a0f018
--- /dev/null
+++ b/spec/data/cookbooks/starter/files/sample.txt
@@ -0,0 +1 @@
+This is a Chef cookbook file. It is used to copy content verbatim on to a server. \ No newline at end of file
diff --git a/spec/data/cookbooks/starter/metadata.rb b/spec/data/cookbooks/starter/metadata.rb
new file mode 100644
index 0000000000..fbd288e9c4
--- /dev/null
+++ b/spec/data/cookbooks/starter/metadata.rb
@@ -0,0 +1,2 @@
+name "starter"
+version "1.0.0"
diff --git a/spec/data/cookbooks/starter/recipes/default.rb b/spec/data/cookbooks/starter/recipes/default.rb
new file mode 100644
index 0000000000..c48b9a4fca
--- /dev/null
+++ b/spec/data/cookbooks/starter/recipes/default.rb
@@ -0,0 +1,4 @@
+# This is a Chef recipe file. It can be used to specify resources which will
+# apply configuration to a server.
+
+# For more information, see the documentation: https://docs.chef.io/essentials_cookbook_recipes.html
diff --git a/spec/unit/cookbook/chefignore_spec.rb b/spec/unit/cookbook/chefignore_spec.rb
index 95b9295f50..606e8d8007 100644
--- a/spec/unit/cookbook/chefignore_spec.rb
+++ b/spec/unit/cookbook/chefignore_spec.rb
@@ -18,32 +18,52 @@
require "spec_helper"
describe Chef::Cookbook::Chefignore do
- before do
- @chefignore = Chef::Cookbook::Chefignore.new(File.join(CHEF_SPEC_DATA, "cookbooks"))
- end
+ let(:chefignore) { described_class.new(File.join(CHEF_SPEC_DATA, "cookbooks")) }
it "loads the globs in the chefignore file" do
- expect(@chefignore.ignores).to match_array(%w{recipes/ignoreme.rb ignored})
+ expect(chefignore.ignores).to match_array(%w{recipes/ignoreme.rb ignored})
end
it "removes items from an array that match the ignores" do
file_list = %w{ recipes/ignoreme.rb recipes/dontignoreme.rb }
- expect(@chefignore.remove_ignores_from(file_list)).to eq(%w{recipes/dontignoreme.rb})
+ expect(chefignore.remove_ignores_from(file_list)).to eq(%w{recipes/dontignoreme.rb})
end
it "determines if a file is ignored" do
- expect(@chefignore.ignored?("ignored")).to be_truthy
- expect(@chefignore.ignored?("recipes/ignoreme.rb")).to be_truthy
- expect(@chefignore.ignored?("recipes/dontignoreme.rb")).to be_falsey
+ expect(chefignore.ignored?("ignored")).to be_truthy
+ expect(chefignore.ignored?("recipes/ignoreme.rb")).to be_truthy
+ expect(chefignore.ignored?("recipes/dontignoreme.rb")).to be_falsey
end
context "when using the single cookbook pattern" do
- before do
- @chefignore = Chef::Cookbook::Chefignore.new(File.join(CHEF_SPEC_DATA, "standalone_cookbook"))
+ let(:chefignore) { described_class.new(File.join(CHEF_SPEC_DATA, "cookbooks/starter")) }
+
+ it "loads the globs in the chefignore file" do
+ expect(chefignore.ignores).to match_array(%w{recipes/default.rb ignored})
+ end
+ end
+
+ context "when cookbook has it's own chefignore" do
+ let(:chefignore) { described_class.new(File.join(CHEF_SPEC_DATA, "cookbooks/starter")) }
+
+ it "loads the globs in the chefignore file" do
+ expect(chefignore.ignores).to match_array(%w{recipes/default.rb ignored})
end
+ end
+
+ context "when cookbook don't have own chefignore" do
+ let(:chefignore) { described_class.new(File.join(CHEF_SPEC_DATA, "cookbooks/apache2")) }
+
+ it "loads the globs in the chefignore file of cookbooks dir" do
+ expect(chefignore.ignores).to match_array(%w{recipes/ignoreme.rb ignored})
+ end
+ end
+
+ context "when using the single cookbook pattern" do
+ let(:chefignore) { described_class.new(File.join(CHEF_SPEC_DATA, "standalone_cookbook")) }
it "loads the globs in the chefignore file" do
- expect(@chefignore.ignores).to match_array(%w{recipes/ignoreme.rb ignored vendor/bundle/*})
+ expect(chefignore.ignores).to match_array(%w{recipes/ignoreme.rb ignored vendor/bundle/*})
end
end
end
diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb
index c747f14dd0..a09bbd043f 100644
--- a/spec/unit/cookbook_loader_spec.rb
+++ b/spec/unit/cookbook_loader_spec.rb
@@ -101,7 +101,7 @@ describe Chef::CookbookLoader do
cookbook_loader.each_key do |cookbook_name|
seen << cookbook_name
end
- expect(seen).to eq %w{angrybash apache2 borken ignorken irssi java name-mismatch openldap preseed supports-platform-constraints wget}
+ expect(seen).to eq %w{angrybash apache2 borken ignorken irssi java name-mismatch openldap preseed starter supports-platform-constraints wget}
end
end
diff --git a/spec/unit/cookbook_uploader_spec.rb b/spec/unit/cookbook_uploader_spec.rb
index 2adecfaa82..07ff303274 100644
--- a/spec/unit/cookbook_uploader_spec.rb
+++ b/spec/unit/cookbook_uploader_spec.rb
@@ -21,9 +21,10 @@ require "spec_helper"
describe Chef::CookbookUploader do
let(:http_client) { double("Chef::ServerAPI") }
+ let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "cookbooks") }
let(:cookbook_loader) do
- loader = Chef::CookbookLoader.new(File.join(CHEF_SPEC_DATA, "cookbooks"))
+ loader = Chef::CookbookLoader.new(cookbook_path)
loader.load_cookbooks
loader.cookbooks_by_name["apache2"].identifier = apache2_identifier
loader.cookbooks_by_name["java"].identifier = java_identifier
@@ -55,6 +56,10 @@ describe Chef::CookbookUploader do
let(:uploader) { described_class.new(cookbooks_to_upload, rest: http_client, policy_mode: policy_mode) }
+ before do
+ allow(Chef::Config).to receive(:cookbook_path) { cookbook_path }
+ end
+
it "defaults to not enabling policy mode" do
expect(described_class.new(cookbooks_to_upload, rest: http_client).policy_mode?).to be(false)
end