summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/cookbook_version.rb9
-rw-r--r--spec/unit/cookbook_version_spec.rb37
2 files changed, 43 insertions, 3 deletions
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 420532585a..209b02838e 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -140,9 +140,12 @@ class Chef
def recipe_yml_filenames_by_name
@recipe_ym_filenames_by_name ||= begin
name_map = yml_filenames_by_name(files_for("recipes"))
- root_alias = cookbook_manifest.root_files.find { |record| record[:name] == "root_files/recipe.yml" }
+ root_alias = cookbook_manifest.root_files.find { |record|
+ record[:name] == "root_files/recipe.yml" ||
+ record[:name] == "root_files/recipe.yaml"
+ }
if root_alias
- Chef::Log.error("Cookbook #{name} contains both recipe.yml and and recipes/default.yml, ignoring recipes/default.yml") if name_map["default"]
+ Chef::Log.error("Cookbook #{name} contains both recipe.yml and recipes/default.yml, ignoring recipes/default.yml") if name_map["default"]
name_map["default"] = root_alias[:full_path]
end
name_map
@@ -583,7 +586,7 @@ class Chef
end
def yml_filenames_by_name(records)
- records.select { |record| record[:name] =~ /\.yml$/ }.inject({}) { |memo, record| memo[File.basename(record[:name], ".yml")] = record[:full_path]; memo }
+ records.select { |record| record[:name] =~ /\.(y[a]?ml)$/ }.inject({}) { |memo, record| memo[File.basename(record[:name], File.extname(record[:name]))] = record[:full_path]; memo }
end
def file_vendor
diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb
index 01345e32e7..215b07e049 100644
--- a/spec/unit/cookbook_version_spec.rb
+++ b/spec/unit/cookbook_version_spec.rb
@@ -41,7 +41,44 @@ describe Chef::CookbookVersion do
it "has empty metadata" do
expect(cookbook_version.metadata).to eq(Chef::Cookbook::Metadata.new)
end
+ end
+
+ describe "#recipe_yml_filenames_by_name" do
+ let(:cookbook_version) { Chef::CookbookVersion.new("name", "/tmp/name") }
+
+ def files_for_recipe(extension)
+ [
+ { name: "recipes/default.#{extension}", full_path: "/home/user/repo/cookbooks/test/recipes/default.#{extension}" },
+ { name: "recipes/other.#{extension}", full_path: "/home/user/repo/cookbooks/test/recipes/other.#{extension}" },
+ ]
+ end
+ %w{yml yaml}.each do |extension|
+
+ context "and YAML files are present including a recipes/default.#{extension}" do
+ before(:each) do
+ allow(cookbook_version).to receive(:files_for).with("recipes").and_return(files_for_recipe(extension))
+ end
+
+ context "and manifest does not include a root_files/recipe.#{extension}" do
+ it "returns all YAML recipes with a correct default of default.#{extension}" do
+ expect(cookbook_version.recipe_yml_filenames_by_name).to eq({ "default" => "/home/user/repo/cookbooks/test/recipes/default.#{extension}",
+ "other" => "/home/user/repo/cookbooks/test/recipes/other.#{extension}" })
+ end
+ end
+
+ context "and manifest also includes a root_files/recipe.#{extension}" do
+ let(:root_files) { [{ name: "root_files/recipe.#{extension}", full_path: "/home/user/repo/cookbooks/test/recipe.#{extension}" } ] }
+ before(:each) do
+ allow(cookbook_version.cookbook_manifest).to receive(:root_files).and_return(root_files)
+ end
+ it "returns all YAML recipes with a correct default of recipe.#{extension}" do
+ expect(cookbook_version.recipe_yml_filenames_by_name).to eq({ "default" => "/home/user/repo/cookbooks/test/recipe.#{extension}",
+ "other" => "/home/user/repo/cookbooks/test/recipes/other.#{extension}" })
+ end
+ end
+ end
+ end
end
describe "with a cookbook directory named tatft" do