clogger 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,6 +55,7 @@ class TestClogger < Test::Unit::TestCase
55
55
  assert_equal("302 Found", status)
56
56
  assert_equal({}, headers)
57
57
  body.each { |part| assert false }
58
+ body.close
58
59
  str = str.string
59
60
  r = %r{\Ahome - - \[[^\]]+\] "GET /hello\?goodbye=true HTTP/1.0" 302 -\n\z}
60
61
  assert_match r, str
@@ -134,7 +135,9 @@ class TestClogger < Test::Unit::TestCase
134
135
  'HTTP_COOKIE' => cookie,
135
136
  }
136
137
  req = @req.merge(req)
137
- cl.call(req).last.each { |part| part }
138
+ body = cl.call(req).last
139
+ body.each { |part| part }
140
+ body.close
138
141
  str = str.string
139
142
  assert(str.size > 128)
140
143
  assert_match %r["echo and socat \\o/" "#{cookie}" \d+\.\d{3}], str
@@ -221,6 +224,7 @@ class TestClogger < Test::Unit::TestCase
221
224
  status, headers, body = cl.call(@req)
222
225
  tmp = []
223
226
  body.each { |s| tmp << s }
227
+ body.close
224
228
  assert_equal %w(a b c), tmp
225
229
  str = str.string
226
230
  assert_match %r[" 200 3 \d+\.\d{4}\n\z], str
@@ -279,6 +283,7 @@ class TestClogger < Test::Unit::TestCase
279
283
  cl = Clogger.new(app, :logger => str, :format => '$response_length')
280
284
  status, header, bodies = cl.call(@req)
281
285
  bodies.each { |part| part }
286
+ bodies.close
282
287
  assert_equal "-\n", str.string
283
288
  end
284
289
 
@@ -290,6 +295,7 @@ class TestClogger < Test::Unit::TestCase
290
295
  status, headers, body = cl.call(@req)
291
296
  tmp = []
292
297
  body.each { |s| tmp << s }
298
+ body.close
293
299
  assert_equal %w(a b c), tmp
294
300
  str = str.string
295
301
  assert_match %r[" 200 3 "-" "echo and socat \\o/"\n\z], str
@@ -402,7 +408,7 @@ class TestClogger < Test::Unit::TestCase
402
408
  req = Rack::Utils::HeaderHash.new(@req)
403
409
  app = lambda { |env| [302, [ %w(a) ], []] }
404
410
  cl = Clogger.new(app, :logger => str, :format => Rack_1_0)
405
- assert_nothing_raised { cl.call(req).last.each {} }
411
+ assert_nothing_raised { cl.call(req).last.each {}.close }
406
412
  assert str.size > 0
407
413
  end
408
414
 
@@ -415,7 +421,7 @@ class TestClogger < Test::Unit::TestCase
415
421
  }
416
422
  app = lambda { |env| [302, [ %w(a) ], []] }
417
423
  cl = Clogger.new(app, :logger => str, :format => Rack_1_0)
418
- assert_nothing_raised { cl.call(req).last.each {} }
424
+ assert_nothing_raised { cl.call(req).last.each {}.close }
419
425
  assert str.size > 0
420
426
  end
421
427
 
@@ -425,7 +431,7 @@ class TestClogger < Test::Unit::TestCase
425
431
  r = nil
426
432
  app = lambda { |env| [302, [ %w(a) ], [FooString.new(body)]] }
427
433
  cl = Clogger.new(app, :logger => str, :format => '$body_bytes_sent')
428
- assert_nothing_raised { cl.call(@req).last.each { |x| r = x } }
434
+ assert_nothing_raised { cl.call(@req).last.each { |x| r = x }.close }
429
435
  assert str.size > 0
430
436
  assert_equal body.size.to_s << "\n", str.string
431
437
  assert_equal r, body
@@ -0,0 +1,140 @@
1
+ # -*- encoding: binary -*-
2
+ $stderr.sync = $stdout.sync = true
3
+ require "test/unit"
4
+ require "date"
5
+ require "stringio"
6
+ require "rack"
7
+ require "clogger"
8
+
9
+ class MyBody < Struct.new(:to_path, :closed)
10
+ def each(&block)
11
+ raise RuntimeError, "each should never get called"
12
+ end
13
+
14
+ def close
15
+ self.closed = true
16
+ end
17
+ end
18
+
19
+ class TestCloggerToPath < Test::Unit::TestCase
20
+
21
+ def setup
22
+ @req = {
23
+ "REQUEST_METHOD" => "GET",
24
+ "HTTP_VERSION" => "HTTP/1.0",
25
+ "HTTP_USER_AGENT" => 'echo and socat \o/',
26
+ "PATH_INFO" => "/",
27
+ "QUERY_STRING" => "",
28
+ "rack.errors" => $stderr,
29
+ "rack.input" => File.open('/dev/null', 'rb'),
30
+ "REMOTE_ADDR" => '127.0.0.1',
31
+ }
32
+ end
33
+
34
+ def test_wraps_to_path
35
+ logger = StringIO.new
36
+ tmp = Tempfile.new('')
37
+ b = nil
38
+ app = Rack::Builder.new do
39
+ tmp.syswrite(' ' * 365)
40
+ h = {
41
+ 'Content-Length' => '0',
42
+ 'Content-Type' => 'text/plain',
43
+ }
44
+ use Clogger,
45
+ :logger => logger,
46
+ :reentrant => true,
47
+ :format => '$body_bytes_sent $status'
48
+ run lambda { |env| [ 200, h, b = MyBody.new(tmp.path) ] }
49
+ end.to_app
50
+
51
+ status, headers, body = app.call(@req)
52
+ assert_instance_of(Clogger::ToPath, body)
53
+ assert logger.string.empty?
54
+ assert_equal tmp.path, body.to_path
55
+ body.close
56
+ assert b.closed, "close passed through"
57
+ assert_equal "365 200\n", logger.string
58
+ end
59
+
60
+ def test_wraps_to_path_dev_fd
61
+ logger = StringIO.new
62
+ tmp = Tempfile.new('')
63
+ b = nil
64
+ app = Rack::Builder.new do
65
+ tmp.syswrite(' ' * 365)
66
+ h = {
67
+ 'Content-Length' => '0',
68
+ 'Content-Type' => 'text/plain',
69
+ }
70
+ use Clogger,
71
+ :logger => logger,
72
+ :reentrant => true,
73
+ :format => '$body_bytes_sent $status'
74
+ run lambda { |env| [ 200, h, b = MyBody.new("/dev/fd/#{tmp.fileno}") ] }
75
+ end.to_app
76
+
77
+ status, headers, body = app.call(@req)
78
+ assert_instance_of(Clogger::ToPath, body)
79
+ assert logger.string.empty?
80
+ assert_equal "/dev/fd/#{tmp.fileno}", body.to_path
81
+ body.close
82
+ assert b.closed
83
+ assert_equal "365 200\n", logger.string
84
+ end
85
+
86
+ def test_wraps_to_path_to_io
87
+ logger = StringIO.new
88
+ tmp = Tempfile.new('')
89
+ def tmp.to_io
90
+ @to_io_called = super
91
+ end
92
+ def tmp.to_path
93
+ path
94
+ end
95
+ app = Rack::Builder.new do
96
+ tmp.syswrite(' ' * 365)
97
+ tmp.sysseek(0)
98
+ h = {
99
+ 'Content-Length' => '0',
100
+ 'Content-Type' => 'text/plain',
101
+ }
102
+ use Clogger,
103
+ :logger => logger,
104
+ :reentrant => true,
105
+ :format => '$body_bytes_sent $status'
106
+ run lambda { |env| [ 200, h, tmp ] }
107
+ end.to_app
108
+
109
+ status, headers, body = app.call(@req)
110
+ assert_instance_of(Clogger::ToPath, body)
111
+ body.to_path
112
+ assert_kind_of IO, tmp.instance_variable_get(:@to_io_called)
113
+ assert logger.string.empty?
114
+ assert ! tmp.closed?
115
+ body.close
116
+ assert tmp.closed?
117
+ assert_equal "365 200\n", logger.string
118
+ end
119
+
120
+ def test_does_not_wrap_to_path
121
+ logger = StringIO.new
122
+ app = Rack::Builder.new do
123
+ h = {
124
+ 'Content-Length' => '3',
125
+ 'Content-Type' => 'text/plain',
126
+ }
127
+ use Clogger,
128
+ :logger => logger,
129
+ :reentrant => true,
130
+ :format => '$body_bytes_sent $status'
131
+ run lambda { |env| [ 200, h, [ "hi\n" ] ] }
132
+ end.to_app
133
+ status, headers, body = app.call(@req)
134
+ assert_instance_of(Clogger, body)
135
+ assert logger.string.empty?
136
+ body.close
137
+ assert ! logger.string.empty?
138
+ end
139
+
140
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloggers
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-21 00:00:00 +00:00
12
+ date: 2010-06-06 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,6 +38,7 @@ extra_rdoc_files:
38
38
  - lib/clogger/format.rb
39
39
  - lib/clogger/pure.rb
40
40
  - ext/clogger_ext/clogger.c
41
+ - LICENSE
41
42
  files:
42
43
  - .document
43
44
  - .gitignore
@@ -47,6 +48,7 @@ files:
47
48
  - GIT-VERSION-FILE
48
49
  - GIT-VERSION-GEN
49
50
  - GNUmakefile
51
+ - LICENSE
50
52
  - NEWS
51
53
  - README
52
54
  - Rakefile
@@ -59,6 +61,7 @@ files:
59
61
  - lib/clogger/pure.rb
60
62
  - setup.rb
61
63
  - test/test_clogger.rb
64
+ - test/test_clogger_to_path.rb
62
65
  has_rdoc: true
63
66
  homepage: http://clogger.rubyforge.org/
64
67
  licenses: []
@@ -92,3 +95,4 @@ specification_version: 3
92
95
  summary: configurable request logging for Rack
93
96
  test_files:
94
97
  - test/test_clogger.rb
98
+ - test/test_clogger_to_path.rb