summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2013-09-18 21:33:33 -0700
committerNoah Kantrowitz <noah@coderanger.net>2014-10-04 13:52:45 -0700
commit2a18b135f2d0337e4fa23fd1fa9aa2071807b090 (patch)
treef99f1d0ecc0b0becd24ed7f050b9a5996e7aaa2c /spec
parent3b207090758210193df0502e988068f56d7c2b37 (diff)
downloadchef-2a18b135f2d0337e4fa23fd1fa9aa2071807b090.tar.gz
Tests for new loader behavior.
Conflicts: spec/unit/cookbook_version_spec.rb
Diffstat (limited to 'spec')
-rw-r--r--spec/data/cb_version_cookbooks/cookbook2/files/test.txt0
-rw-r--r--spec/data/cb_version_cookbooks/cookbook2/templates/test.erb0
-rw-r--r--spec/unit/cookbook_version_spec.rb49
3 files changed, 46 insertions, 3 deletions
diff --git a/spec/data/cb_version_cookbooks/cookbook2/files/test.txt b/spec/data/cb_version_cookbooks/cookbook2/files/test.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/data/cb_version_cookbooks/cookbook2/files/test.txt
diff --git a/spec/data/cb_version_cookbooks/cookbook2/templates/test.erb b/spec/data/cb_version_cookbooks/cookbook2/templates/test.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/data/cb_version_cookbooks/cookbook2/templates/test.erb
diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb
index f20bc3766a..4ee73151b4 100644
--- a/spec/unit/cookbook_version_spec.rb
+++ b/spec/unit/cookbook_version_spec.rb
@@ -98,11 +98,12 @@ describe Chef::CookbookVersion do
describe "with a cookbook directory named tatft" do
MD5 = /[0-9a-f]{32}/
+ let(:cookbook) { 'taftft' }
before do
@cookbook = Hash.new { |hash, key| hash[key] = [] }
- @cookbook_root = File.join(CHEF_SPEC_DATA, 'cb_version_cookbooks', 'tatft')
+ @cookbook_root = File.join(CHEF_SPEC_DATA, 'cb_version_cookbooks', cookbook)
# Dunno if the paths here are representitive of what is set by CookbookLoader...
@cookbook[:attribute_filenames] = Dir[File.join(@cookbook_root, 'attributes', '**', '*.rb')]
@@ -115,14 +116,13 @@ describe Chef::CookbookVersion do
@cookbook[:provider_filenames] = Dir[File.join(@cookbook_root, 'providers', '**', '*.rb')]
@cookbook[:root_filenames] = Array(File.join(@cookbook_root, 'README.rdoc'))
@cookbook[:metadata_filenames] = Array(File.join(@cookbook_root, 'metadata.json'))
-
end
describe "and a cookbook with the same name" do
before do
# Currently the cookbook loader finds all the files then tells CookbookVersion
# where they are.
- @cookbook_version = Chef::CookbookVersion.new("tatft", @cookbook_root)
+ @cookbook_version = Chef::CookbookVersion.new(cookbook, @cookbook_root)
@cookbook_version.attribute_filenames = @cookbook[:attribute_filenames]
@cookbook_version.definition_filenames = @cookbook[:definition_filenames]
@@ -351,6 +351,49 @@ describe Chef::CookbookVersion do
end
end
+ context 'when the cookbook has un-scoped files/templates' do
+ let(:cookbook) { 'cookbook2' }
+
+ before do
+ @cookbook_version = Chef::CookbookVersion.new(cookbook, @cookbook_root)
+ @cookbook_version.attribute_filenames = @cookbook[:attribute_filenames]
+ @cookbook_version.definition_filenames = @cookbook[:definition_filenames]
+ @cookbook_version.recipe_filenames = @cookbook[:recipe_filenames]
+ @cookbook_version.template_filenames = @cookbook[:template_filenames]
+ @cookbook_version.file_filenames = @cookbook[:file_filenames]
+ @cookbook_version.library_filenames = @cookbook[:library_filenames]
+ @cookbook_version.resource_filenames = @cookbook[:resource_filenames]
+ @cookbook_version.provider_filenames = @cookbook[:provider_filenames]
+ @cookbook_version.root_filenames = @cookbook[:root_filenames]
+ @cookbook_version.metadata_filenames = @cookbook[:metadata_filenames]
+ end
+
+ it "should see a template" do
+ @cookbook_version.should have_template_for_node(@node, "test.erb")
+ end
+
+ it "should see a template using an array lookup" do
+ @cookbook_version.should have_template_for_node(@node, ["test.erb"])
+ end
+
+ it "should see a template using an array lookup with non-existant elements" do
+ @cookbook_version.should have_template_for_node(@node, ["missing.txt", "test.erb"])
+ end
+
+ it "should see a file" do
+ @cookbook_version.should have_cookbook_file_for_node(@node, "test.txt")
+ end
+
+ it "should see a file using an array lookup" do
+ @cookbook_version.should have_cookbook_file_for_node(@node, ["test.txt"])
+ end
+
+ it "should see a file using an array lookup with non-existant elements" do
+ @cookbook_version.should have_cookbook_file_for_node(@node, ["missing.txt", "test.txt"])
+ end
+
+ end
+
end