summaryrefslogtreecommitdiff
path: root/spec/functional
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-09-04 21:38:07 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-09-07 10:44:26 -0700
commit3fb87cc744d1e1134476496dedc9125a25add859 (patch)
tree3f31bf92ef0ed2a50fdff54e23c5611db6b60ce9 /spec/functional
parentc8b1e30a8b558c29a1ce1cc6a5a1e5de56534d22 (diff)
downloadchef-3fb87cc744d1e1134476496dedc9125a25add859.tar.gz
Print out request and response body on non-2xx responsejk/http-error-log
Diffstat (limited to 'spec/functional')
-rw-r--r--spec/functional/http/simple_spec.rb58
1 files changed, 57 insertions, 1 deletions
diff --git a/spec/functional/http/simple_spec.rb b/spec/functional/http/simple_spec.rb
index 092d164342..fec71351df 100644
--- a/spec/functional/http/simple_spec.rb
+++ b/spec/functional/http/simple_spec.rb
@@ -80,5 +80,61 @@ describe Chef::HTTP::Simple do
end
it_behaves_like "downloading all the things"
-end
+ context "when Chef::Log.level = :debug" do
+ before do
+ Chef::Log.level = :debug
+ @debug_log = ''
+ Chef::Log.stub(:debug) { |str| @debug_log << str }
+ end
+
+ let(:source) { 'http://localhost:9000' }
+
+ it "Logs the request and response for 200's but not the body" do
+ http_client.get('http://localhost:9000/nyan_cat.png')
+ expect(@debug_log).to match(/200/)
+ expect(@debug_log).to match(/HTTP Request Header Data/)
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
+ expect(@debug_log).not_to match(/HTTP Request Body/)
+ expect(@debug_log).not_to match(/HTTP Response Body/)
+ expect(@debug_log).not_to match(/Your request is just terrible./)
+ end
+
+ it "Logs the request and response for 200 POST, but not the body" do
+ http_client.post('http://localhost:9000/posty', 'hithere')
+ expect(@debug_log).to match(/200/)
+ expect(@debug_log).to match(/HTTP Request Header Data/)
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
+ expect(@debug_log).not_to match(/HTTP Request Body/)
+ expect(@debug_log).not_to match(/hithere/)
+ expect(@debug_log).not_to match(/HTTP Response Body/)
+ expect(@debug_log).not_to match(/Your request is just terrible./)
+ end
+
+ it "Logs the request and response and bodies for 400 response" do
+ expect do
+ http_client.get('http://localhost:9000/bad_request')
+ end.to raise_error(Net::HTTPServerException)
+ expect(@debug_log).to match(/400/)
+ expect(@debug_log).to match(/HTTP Request Header Data/)
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
+ expect(@debug_log).not_to match(/HTTP Request Body/)
+ expect(@debug_log).not_to match(/hithere/)
+ expect(@debug_log).to match(/HTTP Response Body/)
+ expect(@debug_log).to match(/Your request is just terrible./)
+ end
+
+ it "Logs the request and response and bodies for 400 POST response" do
+ expect do
+ http_client.post('http://localhost:9000/bad_request', 'hithere')
+ end.to raise_error(Net::HTTPServerException)
+ expect(@debug_log).to match(/400/)
+ expect(@debug_log).to match(/HTTP Request Header Data/)
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
+ expect(@debug_log).to match(/HTTP Request Body/)
+ expect(@debug_log).to match(/hithere/)
+ expect(@debug_log).to match(/HTTP Response Body/)
+ expect(@debug_log).to match(/Your request is just terrible./)
+ end
+ end
+end