diff options
author | danielsdeleo <dan@getchef.com> | 2014-08-07 16:32:02 -0700 |
---|---|---|
committer | danielsdeleo <dan@getchef.com> | 2014-08-12 11:03:10 -0700 |
commit | 2577c6f8f503dd6484ca656c9b3780c52cc6e038 (patch) | |
tree | f6f53cb2ac2d03305c9ca849e30cecb99303b0c9 /spec/unit/cookbook/cookbook_version_loader_spec.rb | |
parent | 89427a59886b0724a5a1101dde7ea1a1def1c67a (diff) | |
download | chef-2577c6f8f503dd6484ca656c9b3780c52cc6e038.tar.gz |
Make `name` a required attribute in metadata
Diffstat (limited to 'spec/unit/cookbook/cookbook_version_loader_spec.rb')
-rw-r--r-- | spec/unit/cookbook/cookbook_version_loader_spec.rb | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/spec/unit/cookbook/cookbook_version_loader_spec.rb b/spec/unit/cookbook/cookbook_version_loader_spec.rb index c8292de762..ad10f24573 100644 --- a/spec/unit/cookbook/cookbook_version_loader_spec.rb +++ b/spec/unit/cookbook/cookbook_version_loader_spec.rb @@ -108,7 +108,7 @@ describe Chef::Cookbook::CookbookVersionLoader do end - context "when a cookbook has an invalid metadata file [CHEF-2923]" do + context "when a cookbook has a metadata file with a ruby error [CHEF-2923]" do let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "invalid-metadata-chef-repo/invalid-metadata") } @@ -136,6 +136,43 @@ describe Chef::Cookbook::CookbookVersionLoader do end + context "when a cookbook has a metadata file with invalid metadata" do + + let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "incomplete-metadata-chef-repo/incomplete-metadata") } + + let(:error_message) do + "Cookbook loaded at path(s) [#{cookbook_path}] has invalid metadata: The `name' attribute is required in cookbook metadata" + end + + it "raises an error when loading with #load!" do + expect { cookbook_loader.load! }.to raise_error(Chef::Exceptions::MetadataNotValid, error_message) + end + + it "raises an error when called with #load" do + expect { cookbook_loader.load }.to raise_error(Chef::Exceptions::MetadataNotValid, error_message) + end + + it "uses the inferred cookbook name [CHEF-2923]" do + # This behavior is intended to support the CHEF-2923 feature where + # invalid metadata doesn't prevent you from uploading other cookbooks. + # + # The metadata is the definitive source of the cookbook name, but if + # the metadata is incomplete/invalid, we can't read the name from it. + # + # The CookbookLoader stores CookbookVersionLoaders in a Hash with + # cookbook names as the keys, and finds the loader in this Hash to call + # #load on it when the user runs a command like `knife cookbook upload specific-cookbook` + # + # Most of the time this will work, but if the user tries to upload a + # specific cookbook by name, has customized that cookbook's name (so it + # doesn't match the inferred name), and that metadata file has a syntax + # error, we might report a "cookbook not found" error instead of the + # metadata syntax error that is the actual cause. + expect(cookbook_loader.cookbook_name).to eq(:"incomplete-metadata") + end + + end + end end |