diff options
author | danielsdeleo <dan@getchef.com> | 2014-08-05 16:59:23 -0700 |
---|---|---|
committer | danielsdeleo <dan@getchef.com> | 2014-08-12 11:03:09 -0700 |
commit | da1b4953fa444bebfb4f71c15849db108eb52462 (patch) | |
tree | 90a7343cb8ce5f96ceb5b89cd8f05affcb4af732 /spec/unit/cookbook_loader_spec.rb | |
parent | 4f77c451b18ba6cab5d23ba4cd1b23532d0bd856 (diff) | |
download | chef-da1b4953fa444bebfb4f71c15849db108eb52462.tar.gz |
Ignore non-critical errors when finding the cookbook set
https://tickets.opscode.com/browse/CHEF-2923
When running `knife cookbook upload SPECIFIC_COOKBOOK`, errors in
metadata files for unrelated cookbooks should not be raised; however, we
must evaluate the metadata for all cookbooks in order to allow the
metadata `name` attribute to be different from the cookbook directory's
basename. Therefore, we must tolerate errors in metadata.rb and re-raise
them only when attempting to load the cookbook with the invalid
metadata.
Diffstat (limited to 'spec/unit/cookbook_loader_spec.rb')
-rw-r--r-- | spec/unit/cookbook_loader_spec.rb | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index 8c1a0886c2..d5d585b8e1 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -167,10 +167,26 @@ describe Chef::CookbookLoader do cookbook_loader.metadata[:openldap].should be_a_kind_of(Chef::Cookbook::Metadata) end - end # after loading cookbooks + end # referencing cookbook files end # loading all cookbooks + context "loading all cookbooks when one has invalid metadata" do + + let(:repo_paths) do + [ + File.join(CHEF_SPEC_DATA, "kitchen"), + File.join(CHEF_SPEC_DATA, "cookbooks"), + File.join(CHEF_SPEC_DATA, "invalid-metadata-chef-repo") + ] + end + + it "does not squelch the exception" do + expect { cookbook_loader.load_cookbooks }.to raise_error("THIS METADATA HAS A BUG") + end + + end + describe "loading only one cookbook" do before(:each) do cookbook_loader.load_cookbook("openldap") @@ -217,6 +233,25 @@ describe Chef::CookbookLoader do cookbook_loader["apache2"].should be_a_kind_of(Chef::CookbookVersion) end + context "when an unrelated cookbook has invalid metadata" do + + let(:repo_paths) do + [ + File.join(CHEF_SPEC_DATA, "kitchen"), + File.join(CHEF_SPEC_DATA, "cookbooks"), + File.join(CHEF_SPEC_DATA, "invalid-metadata-chef-repo") + ] + end + + it "ignores the invalid cookbook" do + expect { cookbook_loader["openldap"] }.to_not raise_error + end + + it "surfaces the exception if the cookbook is loaded later" do + expect { cookbook_loader["invalid-metadata"] }.to raise_error("THIS METADATA HAS A BUG") + end + + end describe "loading all cookbooks after loading only one cookbook" do before(:each) do |