diff options
author | Tim Smith <tsmith@chef.io> | 2018-03-12 12:36:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-12 12:36:14 -0700 |
commit | 797fe20ea3b529a36dc6a88e6101d3544b9ecb70 (patch) | |
tree | 23213fffe8302dda586746fc2c16412bfc3193b0 /spec | |
parent | de0ed26e4b0a42f3af827912339ecae65253b52b (diff) | |
parent | 2e94dd8d733b9bae92228f4eca2dcdb0c58594c3 (diff) | |
download | chef-797fe20ea3b529a36dc6a88e6101d3544b9ecb70.tar.gz |
Merge pull request #6253 from jeunito/feat/5556
Knife should give a useful error when the chef_server_url isn't a chef server API
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/server_api_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/unit/server_api_spec.rb b/spec/unit/server_api_spec.rb index 3f1d9b0e90..c64f42d358 100644 --- a/spec/unit/server_api_spec.rb +++ b/spec/unit/server_api_spec.rb @@ -58,6 +58,36 @@ describe Chef::ServerAPI do end end + describe "#get" do + context "when response is 404" do + context "body data is not json" do + it "throws not a Chef server exception" do + net_http_not_found = double() + allow(net_http_not_found).to receive(:kind_of?).and_return(Net::HTTPNotFound) + allow(net_http_not_found).to receive(:body).and_return("Not Found") + + api = described_class.new(url, raw_key: SIGNING_KEY_DOT_PEM) + allow(api).to receive(:request).and_raise(Net::HTTPServerException.new("", net_http_not_found)) + + expect { api.get("/nodes") }.to raise_error(Chef::Exceptions::NotAChefServerException) + end + end + + context "body data is json" do + it "bubbles up Exception" do + net_http_not_found = double() + allow(net_http_not_found).to receive(:kind_of?).and_return(Net::HTTPNotFound) + allow(net_http_not_found).to receive(:body).and_return("{}") + + api = described_class.new(url, raw_key: SIGNING_KEY_DOT_PEM) + allow(api).to receive(:request).and_raise(Net::HTTPServerException.new("", net_http_not_found)) + + expect { api.get("/nodes") }.to raise_error(Net::HTTPServerException) + end + end + end + end + context "versioned apis" do class VersionedClassV0 extend Chef::Mixin::VersionedAPI |