summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivek Singh <vivek.singh@msystechnologies.com>2019-10-07 21:42:11 +0530
committerVivek Singh <vivek.singh@msystechnologies.com>2019-10-28 14:06:22 +0530
commit33c9f7e83df1ce92f417eee5b5d3a76b9acdf66c (patch)
tree87e9738072397bd0635ad5af94b6673f0c30f1db
parent7686384b8fca141673abee311b3d986bdd91dc05 (diff)
downloadchef-33c9f7e83df1ce92f417eee5b5d3a76b9acdf66c.tar.gz
Add chefignore unit test cases
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
-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
5 files changed, 46 insertions, 11 deletions
diff --git a/spec/data/cookbooks/starter/chefignore b/spec/data/cookbooks/starter/chefignore
new file mode 100644
index 0000000000..9e0f3d8622
--- /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 \ No newline at end of file
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