summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-10-06 11:15:41 +0100
committerGitHub <noreply@github.com>2016-10-06 11:15:41 +0100
commit81300c7168df0c3e6171b3dbfe09f92c28b6f2a1 (patch)
tree594cc3c9ad10349d4132d53d5751153aa7fa642a
parent6ae914958056476eedc3ff1a537c540d71015d20 (diff)
parent5338410abfb52c7675fea4db59c9754879cac4b9 (diff)
downloadchef-81300c7168df0c3e6171b3dbfe09f92c28b6f2a1.tar.gz
Merge pull request #5417 from chef/lcg/issue5089
Fix for "Chefspec template rendering fails when cookbook_name != directory name"
-rw-r--r--lib/chef/cookbook/file_system_file_vendor.rb15
-rw-r--r--spec/unit/cookbook/file_vendor_spec.rb15
2 files changed, 22 insertions, 8 deletions
diff --git a/lib/chef/cookbook/file_system_file_vendor.rb b/lib/chef/cookbook/file_system_file_vendor.rb
index 91f1c9f853..8088ed00cd 100644
--- a/lib/chef/cookbook/file_system_file_vendor.rb
+++ b/lib/chef/cookbook/file_system_file_vendor.rb
@@ -37,20 +37,19 @@ class Chef
def initialize(manifest, *repo_paths)
@cookbook_name = manifest[:cookbook_name]
@repo_paths = repo_paths.flatten
- raise ArgumentError, "You must specify at least one repo path" if @repo_paths.empty?
+ raise ArgumentError, "You must specify at least one repo path" if repo_paths.empty?
+ end
+
+ def cookbooks
+ @cookbooks ||= Chef::CookbookLoader.new(repo_paths).load_cookbooks
end
# Implements abstract base's requirement. It looks in the
# Chef::Config.cookbook_path file hierarchy for the requested
# file.
def get_filename(filename)
- location = @repo_paths.inject(nil) do |memo, basepath|
- candidate_location = File.join(basepath, @cookbook_name, filename)
- memo = candidate_location if File.exist?(candidate_location)
- memo
- end
- raise "File #{filename} does not exist for cookbook #{@cookbook_name}" unless location
-
+ location = File.join(cookbooks[cookbook_name].root_dir, filename) if cookbooks.has_key?(cookbook_name)
+ raise "File #{filename} does not exist for cookbook #{cookbook_name}" unless location && File.exist?(location)
location
end
diff --git a/spec/unit/cookbook/file_vendor_spec.rb b/spec/unit/cookbook/file_vendor_spec.rb
index 139a5932f9..164fbd8177 100644
--- a/spec/unit/cookbook/file_vendor_spec.rb
+++ b/spec/unit/cookbook/file_vendor_spec.rb
@@ -94,4 +94,19 @@ describe Chef::Cookbook::FileVendor do
end
+ context "when vendoring a cookbook with a name mismatch" do
+ let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "cookbooks") }
+
+ # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest
+ let(:manifest) { { :cookbook_name => "name-mismatch" } }
+
+ before do
+ file_vendor_class.fetch_from_disk(cookbook_path)
+ end
+
+ it "retrieves the file from the correct location based on path to the cookbook that conatins the correct name metadata" do
+ file_vendor = file_vendor_class.create_from_manifest(manifest)
+ file_vendor.get_filename("metadata.rb")
+ end
+ end
end