diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/http/simple_spec.rb | 58 | ||||
-rw-r--r-- | spec/support/shared/functional/http.rb | 9 | ||||
-rw-r--r-- | spec/unit/rest_spec.rb | 2 |
3 files changed, 66 insertions, 3 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 diff --git a/spec/support/shared/functional/http.rb b/spec/support/shared/functional/http.rb index c362ecaa18..9a3389306d 100644 --- a/spec/support/shared/functional/http.rb +++ b/spec/support/shared/functional/http.rb @@ -155,6 +155,14 @@ module ChefHTTPShared } ) + @api.post('/posty', 200, 'Hi!') + + # + # 400 with an error + # + @api.get('/bad_request', 400, '{ "error": [ "Your request is just terrible." ] }') + @api.post('/bad_request', 400, '{ "error": [ "Your request is just terrible." ] }') + end def stop_tiny_server @@ -239,4 +247,3 @@ shared_examples_for "downloading all the things" do it_behaves_like "a 403 after a successful request when reusing the request object" end end - diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb index f20672ef25..3ad822193b 100644 --- a/spec/unit/rest_spec.rb +++ b/spec/unit/rest_spec.rb @@ -540,7 +540,7 @@ describe Chef::REST do let(:request_mock) { {} } let(:http_response) do - http_response = Net::HTTPSuccess.new("1.1",200, "it-works") + http_response = Net::HTTPSuccess.new("1.1",'200', "it-works") http_response.stub(:read_body) http_response.should_not_receive(:body) |