summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-06-01 10:28:23 -0700
committerGitHub <noreply@github.com>2021-06-01 10:28:23 -0700
commit76fd15fbec7c4831ac14b958c8b80ea3fa216bc4 (patch)
tree26df5efee631c24908672f44365ab11f4369cbb0 /spec
parent3aa46e78590bcacbd43800b95d4adc3169c6984e (diff)
parentd04bb474713bff8773d1bb0a1337ddc4f9027e38 (diff)
downloadchef-76fd15fbec7c4831ac14b958c8b80ea3fa216bc4.tar.gz
Merge pull request #11629 from chef/mp/11354
Support recipes that and in .yaml as well as .yml
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/cookbook_version_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb
index 01345e32e7..4a964f74de 100644
--- a/spec/unit/cookbook_version_spec.rb
+++ b/spec/unit/cookbook_version_spec.rb
@@ -41,7 +41,59 @@ 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("mycb", "/tmp/mycb") }
+
+ 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
+ context "and YAML files present include both a recipes/default.yml and a recipes/default.yaml" do
+ before(:each) do
+ allow(cookbook_version).to receive(:files_for).with("recipes").and_return(
+ [
+ { name: "recipes/default.yml", full_path: "/home/user/repo/cookbooks/test/recipes/default.yml" },
+ { name: "recipes/default.yaml", full_path: "/home/user/repo/cookbooks/test/recipes/default.yaml" },
+ ]
+ )
+ end
+ it "because both are valid and we can't pick, it raises an error that contains the info needed to fix the problem" do
+ expect { cookbook_version.recipe_yml_filenames_by_name }
+ .to raise_error(Chef::Exceptions::AmbiguousYAMLFile, /.*default.yml.*default.yaml.*update the cookbook to remove/)
+ end
+ 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