1 # -*- encoding: binary -*-
2 $stderr.sync = $stdout.sync = true
9 class MyBody < Struct.new(:to_path, :closed)
11 raise RuntimeError, "each should never get called"
19 class TestCloggerToPath < Test::Unit::TestCase
23 "REQUEST_METHOD" => "GET",
24 "HTTP_VERSION" => "HTTP/1.0",
25 "HTTP_USER_AGENT" => 'echo and socat \o/',
28 "rack.errors" => $stderr,
29 "rack.input" => File.open('/dev/null', 'rb'),
30 "REMOTE_ADDR" => '127.0.0.1',
35 assert body.respond_to?(:to_path)
36 assert body.respond_to?("to_path")
38 assert ! body.respond_to?(:to_Path)
39 assert ! body.respond_to?("to_Path")
42 def test_wraps_to_path
44 tmp = Tempfile.new('')
46 app = Rack::Builder.new do
47 tmp.syswrite(' ' * 365)
49 'Content-Length' => '0',
50 'Content-Type' => 'text/plain',
55 :format => '$body_bytes_sent $status'
56 run lambda { |env| [ 200, h, b = MyBody.new(tmp.path) ] }
59 status, headers, body = app.call(@req)
60 assert_instance_of(Clogger, body)
62 assert logger.string.empty?
63 assert_equal tmp.path, body.to_path
65 assert b.closed, "close passed through"
66 assert_equal "365 200\n", logger.string
69 def test_wraps_to_path_dev_fd
71 tmp = Tempfile.new('')
73 app = Rack::Builder.new do
74 tmp.syswrite(' ' * 365)
76 'Content-Length' => '0',
77 'Content-Type' => 'text/plain',
82 :format => '$body_bytes_sent $status'
83 run lambda { |env| [ 200, h, b = MyBody.new("/dev/fd/#{tmp.fileno}") ] }
86 status, headers, body = app.call(@req)
87 assert_instance_of(Clogger, body)
89 assert logger.string.empty?
90 assert_equal "/dev/fd/#{tmp.fileno}", body.to_path
93 assert_equal "365 200\n", logger.string
96 def test_does_not_wrap_to_path
98 app = Rack::Builder.new do
100 'Content-Length' => '3',
101 'Content-Type' => 'text/plain',
106 :format => '$body_bytes_sent $status'
107 run lambda { |env| [ 200, h, [ "hi\n" ] ] }
109 status, headers, body = app.call(@req)
110 assert_instance_of(Clogger, body)
111 assert ! body.respond_to?(:to_path)
112 assert ! body.respond_to?("to_path")
113 assert logger.string.empty?
115 assert ! logger.string.empty?