summaryrefslogtreecommitdiff
path: root/chef/spec/unit/rest_spec.rb
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2012-01-18 18:07:04 -0800
committerDaniel DeLeo <dan@opscode.com>2012-01-18 18:07:04 -0800
commit7c957be1664cee63f0209160b99ab554d15ff4ec (patch)
tree829588e8b838d153d23dba633d4eb29c884e4759 /chef/spec/unit/rest_spec.rb
parentba48a30239ae9e19707338bd184630d45d9601ce (diff)
downloadchef-7c957be1664cee63f0209160b99ab554d15ff4ec.tar.gz
[CHEF-2872] decompress body when request is unsuccessful
Diffstat (limited to 'chef/spec/unit/rest_spec.rb')
-rw-r--r--chef/spec/unit/rest_spec.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb
index d82cc772e1..fff3926b89 100644
--- a/chef/spec/unit/rest_spec.rb
+++ b/chef/spec/unit/rest_spec.rb
@@ -419,6 +419,21 @@ describe Chef::REST do
@log_stringio.string.should match(Regexp.escape('WARN: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
end
+ it "decompresses the JSON error message on an unsuccessful request" do
+ http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
+ http_response.add_field("content-type", "application/json")
+ http_response.add_field("content-encoding", "deflate")
+ unzipped_body = '{ "error":[ "Ears get sore!", "Not even four" ] }'
+ gzipped_body = Zlib::Deflate.deflate(unzipped_body, 1)
+ http_response.stub!(:body).and_return gzipped_body
+ http_response.stub!(:read_body)
+ @rest.stub!(:sleep)
+ @http_client.stub!(:request).and_yield(http_response).and_return(http_response)
+
+ lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError)
+ @log_stringio.string.should match(Regexp.escape('WARN: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
+ end
+
it "should raise an exception on an unsuccessful request" do
http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
http_response.stub!(:body)