diff options
author | Thom May <thom@may.lt> | 2016-07-15 06:59:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-15 06:59:24 -0500 |
commit | 7f2b1604e3ecf357e4a594c3ee8ccf65e5cfaa9e (patch) | |
tree | 77bc5f8cc5bf9984e18fd8b0163d959972f635ab | |
parent | 5fbfde1909e7aec5889633e2708cddfa2ef4645c (diff) | |
parent | d5299f1e1c71c777a54912fa4346607dda3c3e95 (diff) | |
download | chef-7f2b1604e3ecf357e4a594c3ee8ccf65e5cfaa9e.tar.gz |
Merge pull request #5091 from chef/tm/fix_supermarket_share_error
The user must specify a category for a new cookbook
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 20 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_share_spec.rb | 8 |
2 files changed, 11 insertions, 17 deletions
diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index f500ba2182..d55d6c123a 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -113,19 +113,13 @@ class Chef end def get_category(cookbook_name) - begin - data = noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}") - if !data["category"] && data["error_code"] - ui.fatal("Received an error from Supermarket: #{data["error_code"]}. On the first time you upload it, you are required to specify the category you want to share this cookbook to.") - exit(1) - else - data["category"] - end - rescue => e - ui.fatal("Unable to reach Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.") - Chef::Log.debug("\n#{e.backtrace.join("\n")}") - exit(1) - end + data = noauth_rest.get("#{config[:supermarket_site]}/api/v1/cookbooks/#{@name_args[0]}") + data["category"] + rescue => e + return "Other" if e.kind_of?(Net::HTTPServerException) && e.response.code == "404" + ui.fatal("Unable to reach Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.") + Chef::Log.debug("\n#{e.backtrace.join("\n")}") + exit(1) end def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename) diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index 9339114d2a..5ac48539e4 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -83,11 +83,11 @@ describe Chef::Knife::CookbookSiteShare do @knife.run end - it "should print error and exit when given only 1 argument and cannot determine category" do + it "should use a default category when given only 1 argument and cannot determine category" do @knife.name_args = ["cookbook_name"] - expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response) - expect(@knife.ui).to receive(:fatal) - expect { @knife.run }.to raise_error(SystemExit) + expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Net::HTTPServerException.new("404 Not Found", OpenStruct.new(code: "404")) } + expect(@knife).to receive(:do_upload) + expect { @knife.run }.to_not raise_error end it "should print error and exit when given only 1 argument and Chef::ServerAPI throws an exception" do |