summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2021-05-26 12:31:47 -0400
committerMarc A. Paradise <marc.paradise@gmail.com>2021-05-26 12:31:47 -0400
commit0820c04855ab637e4917a6e4fb82582e83de0243 (patch)
treef012fd76c1e2cc99e363640f3d215a39cb36257e /spec/unit
parent30573ca1b0a1517b5cc8fcc99e8faa500e873d49 (diff)
downloadchef-0820c04855ab637e4917a6e4fb82582e83de0243.tar.gz
Support recipes that and in .yaml as well as .yml
This adds support for recipe files that end in the '.yaml' extension in addition to existing support for '.yml', because both are valid and common extensions for yaml files. Of note is that the message we log when a recipes/default.y[a]ml and a root_files/recipe.y[a]ml both exist will be slightly off, in that we don't capture the actual extension of each file. This seems to be more complexity than it was worth, for a message that is shown at the beginning of the run and largely ignored. I also tried to add a bit of localized unit testing for `recipe_yml_filenames_by_name` because we didn't before. Mostly focuses on this use case (yaml, yml both work) but we could probalby improve that by including tests for a mix of yaml/yml files. Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/cookbook_version_spec.rb37
1 files changed, 37 insertions, 0 deletions
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