1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/test_debug_logger.rb
2020-05-09 17:30:48 +03:00

82 lines
1.9 KiB
Ruby

require_relative "helper"
class TestDebugLogger < Minitest::Test
def setup
@debug_logger = Puma::DebugLogger.stdio
end
def test_other_io
with_debug_mode do
debug_logger = Puma::DebugLogger.new(StringIO.new)
debug_logger.error_dump(StandardError.new('ready'))
assert_match %r!#<StandardError: ready>!, debug_logger.ioerr.string
end
end
def test_stdio
debug_logger = Puma::DebugLogger.stdio
assert_equal STDERR, debug_logger.ioerr
end
def test_error_dump_if_debug_false
_, err = capture_io do
@debug_logger.error_dump(StandardError.new('ready'))
end
assert_empty err
end
def test_error_dump_force
_, err = capture_io do
Puma::DebugLogger.stdio.error_dump(StandardError.new('ready'), nil, force: true)
end
assert_match %r!ready!, err
end
def test_error_dump_with_only_error
with_debug_mode do
_, err = capture_io do
Puma::DebugLogger.stdio.error_dump(StandardError.new('ready'), nil)
end
assert_match %r!#<StandardError: ready>!, err
end
end
def test_error_dump_with_env
with_debug_mode do
env = {
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/debug',
'HTTP_X_FORWARDED_FOR' => '8.8.8.8'
}
_, err = capture_io do
Puma::DebugLogger.stdio.error_dump(StandardError.new, env)
end
assert_match %r!Handling request { GET /debug } \(8\.8\.8\.8\)!, err
end
end
def test_error_dump_with_custom_message
with_debug_mode do
_, err = capture_io do
Puma::DebugLogger.stdio.error_dump(StandardError.new, nil, custom_message: 'The client disconnected while we were reading data')
end
assert_match %r!The client disconnected while we were reading data!, err
end
end
private
def with_debug_mode
original_debug, ENV["PUMA_DEBUG"] = ENV["PUMA_DEBUG"], "1"
yield
ensure
ENV["PUMA_DEBUG"] = original_debug
end
end