summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--test/net/http/test_http.rb2
-rw-r--r--test/net/http/test_https.rb5
-rw-r--r--test/net/http/utils.rb6
-rw-r--r--test/open-uri/test_open-uri.rb13
-rw-r--r--test/open-uri/test_ssl.rb23
-rw-r--r--test/webrick/test_httpauth.rb2
-rw-r--r--test/webrick/test_server.rb5
-rw-r--r--test/webrick/utils.rb14
9 files changed, 45 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index 9000a81..f82e40d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Nov 9 20:29:01 2014 Tanaka Akira <akr@fsij.org>
+
+ * test/webrick: Store log in an array.
+
+ * test/net/http: Ditto.
+
+ * test/open-uri: Ditto.
+
Sun Nov 9 18:35:36 2014 Tanaka Akira <akr@fsij.org>
* test/xmlrpc: Refine log test.
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index bd0d960..90336b2 100644
--- a/test/net/http/test_http.rb
+++ b/test/net/http/test_http.rb
@@ -277,7 +277,7 @@ module TestNetHTTP_version_1_1_methods
end
}
assert_equal 1, i
- @log_pattern = nil # server may encount ECONNRESET
+ @log_tester = nil # server may encount ECONNRESET
end
def test_get__implicit_start
diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb
index 89845c5..bff2b4a 100644
--- a/test/net/http/test_https.rb
+++ b/test/net/http/test_https.rb
@@ -117,7 +117,10 @@ class TestNetHTTPS < Test::Unit::TestCase
end
}
assert_match(/certificate verify failed/, ex.message)
- @log_pattern = /ERROR OpenSSL::SSL::SSLError:/
+ @log_tester = lambda {|log|
+ assert_equal(1, log.length)
+ assert_match(/ERROR OpenSSL::SSL::SSLError:/, log[0])
+ }
end
def test_identity_verify_failure
diff --git a/test/net/http/utils.rb b/test/net/http/utils.rb
index 3bf7695..dcd9469 100644
--- a/test/net/http/utils.rb
+++ b/test/net/http/utils.rb
@@ -36,14 +36,14 @@ module TestNetHTTPUtils
@server.shutdown
@server_thread.join
end
- assert_match(@log_pattern, @log.string) if @log_pattern
+ @log_tester.call(@log) if @log_tester
# resume global state
Net::HTTP.version_1_2
end
def spawn_server
- @log = StringIO.new('')
- @log_pattern = /\A\z/
+ @log = []
+ @log_tester = lambda {|log| assert_equal([], log ) }
@config = self.class::CONFIG
server_config = {
:BindAddress => config('host'),
diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb
index 816d7fa..d2d8840 100644
--- a/test/open-uri/test_open-uri.rb
+++ b/test/open-uri/test_open-uri.rb
@@ -14,7 +14,7 @@ class TestOpenURI < Test::Unit::TestCase
end
def with_http(log_is_empty=true)
- log = StringIO.new('')
+ log = []
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
Dir.mktmpdir {|dr|
srv = WEBrick::HTTPServer.new({
@@ -34,7 +34,7 @@ class TestOpenURI < Test::Unit::TestCase
end
}
if log_is_empty
- assert_equal("", log.string)
+ assert_equal([], log)
end
end
@@ -92,7 +92,8 @@ class TestOpenURI < Test::Unit::TestCase
}
server_thread2 = Thread.new {
server_thread.join
- assert_match(%r{ERROR `/not-exist' not found}, server_log.string)
+ assert_equal(1, server_log.length)
+ assert_match(%r{ERROR `/not-exist' not found}, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}
@@ -486,7 +487,8 @@ class TestOpenURI < Test::Unit::TestCase
}
server_thread2 = Thread.new {
server_thread.join
- assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log.string)
+ assert_equal(1, server_log.length)
+ assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}
@@ -505,7 +507,8 @@ class TestOpenURI < Test::Unit::TestCase
}
server_thread2 = Thread.new {
server_thread.join
- assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log.string)
+ assert_equal(1, server_log.length)
+ assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}
diff --git a/test/open-uri/test_ssl.rb b/test/open-uri/test_ssl.rb
index baffd1c..154bcf4 100644
--- a/test/open-uri/test_ssl.rb
+++ b/test/open-uri/test_ssl.rb
@@ -19,7 +19,7 @@ class TestOpenURISSL
end
def with_https(log_is_empty=true)
- log = StringIO.new('')
+ log = []
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
Dir.mktmpdir {|dr|
srv = WEBrick::HTTPServer.new({
@@ -42,7 +42,7 @@ class TestOpenURISSL
th.join
end
if log_is_empty
- assert_equal("", log.string)
+ assert_equal([], log)
end
}
end
@@ -96,14 +96,15 @@ class TestOpenURISSL
}
server_thread2 = Thread.new {
server_thread.join
- assert_match(/ERROR OpenSSL::SSL::SSLError:/, server_log.string)
+ assert_equal(1, server_log.length)
+ assert_match(/ERROR OpenSSL::SSL::SSLError:/, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}
end
def with_https_proxy
- proxy_log = StringIO.new('')
+ proxy_log = []
proxy_logger = WEBrick::Log.new(proxy_log, WEBrick::BasicLog::WARN)
with_https {|srv, dr, url, server_thread, server_log|
srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } )
@@ -116,7 +117,7 @@ class TestOpenURISSL
proxy = WEBrick::HTTPProxyServer.new({
:ServerType => Thread,
:Logger => proxy_logger,
- :AccessLog => [[proxy_access_log=StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT]],
+ :AccessLog => [[proxy_access_log=[], WEBrick::AccessLog::COMMON_LOG_FORMAT]],
:BindAddress => '127.0.0.1',
:Port => 0})
_, proxy_port, _, proxy_host = proxy.listeners[0].addr
@@ -128,7 +129,7 @@ class TestOpenURISSL
proxy_thread.join
end
}
- assert_equal('', proxy_log.string)
+ assert_equal([], proxy_log)
end
def test_proxy_cacert_file
@@ -146,8 +147,9 @@ class TestOpenURISSL
}
proxy_thread2 = Thread.new {
proxy_thread.join
- assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log.string)
- assert_equal('', proxy_log.string)
+ assert_equal(1, proxy_access_log.length)
+ assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log[0])
+ assert_equal([], proxy_log)
}
assert_join_threads([client_thread, proxy_thread2, server_thread])
}
@@ -168,8 +170,9 @@ class TestOpenURISSL
}
proxy_thread2 = Thread.new {
proxy_thread.join
- assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log.string)
- assert_equal('', proxy_log.string)
+ assert_equal(1, proxy_access_log.length)
+ assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log[0])
+ assert_equal([], proxy_log)
}
assert_join_threads([client_thread, proxy_thread2, server_thread])
}
diff --git a/test/webrick/test_httpauth.rb b/test/webrick/test_httpauth.rb
index bf47656..051e252 100644
--- a/test/webrick/test_httpauth.rb
+++ b/test/webrick/test_httpauth.rb
@@ -61,7 +61,6 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
http.request(g){|res| assert_not_equal("hoge", res.body, log.call)}
}
}
- log = log.lines.to_a
log.reject! {|line| /\A\s*\z/ =~ line }
pats = [
/ERROR Basic WEBrick's realm: webrick: password unmatch\./,
@@ -154,7 +153,6 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
end
}
}
- log = log.lines.to_a
log.reject! {|line| /\A\s*\z/ =~ line }
pats = [
/ERROR Digest WEBrick's realm: no credentials in the request\./,
diff --git a/test/webrick/test_server.rb b/test/webrick/test_server.rb
index 40afdb0..e46494a 100644
--- a/test/webrick/test_server.rb
+++ b/test/webrick/test_server.rb
@@ -26,7 +26,7 @@ class TestWEBrickServer < Test::Unit::TestCase
def test_start_exception
stopped = 0
- log = StringIO.new('')
+ log = []
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
assert_raises(SignalException) do
@@ -47,7 +47,8 @@ class TestWEBrickServer < Test::Unit::TestCase
end
assert_equal(stopped, 1)
- assert_match(/FATAL SignalException: SIGTERM/, log.string)
+ assert_equal(1, log.length)
+ assert_match(/FATAL SignalException: SIGTERM/, log[0])
end
def test_callbacks
diff --git a/test/webrick/utils.rb b/test/webrick/utils.rb
index b15ef9a..e1c2344 100644
--- a/test/webrick/utils.rb
+++ b/test/webrick/utils.rb
@@ -32,17 +32,13 @@ module TestWEBrick
module_function
def start_server(klass, config={}, &block)
- log_string = ""
- logger = Object.new
- logger.instance_eval do
- define_singleton_method(:<<) {|msg| log_string << msg }
- end
- log = proc { "webrick log start:\n" + log_string.gsub(/^/, " ").chomp + "\nwebrick log end" }
+ log_ary = []
+ log = proc { "webrick log start:\n" + log_ary.join.gsub(/^/, " ").chomp + "\nwebrick log end" }
server = klass.new({
:BindAddress => "127.0.0.1", :Port => 0,
:ServerType => Thread,
- :Logger => WEBrick::Log.new(logger, WEBrick::BasicLog::WARN),
- :AccessLog => [[logger, ""]]
+ :Logger => WEBrick::Log.new(log_ary, WEBrick::BasicLog::WARN),
+ :AccessLog => [[log_ary, ""]]
}.update(config))
server_thread = server.start
addr = server.listeners[0].addr
@@ -54,7 +50,7 @@ module TestWEBrick
end
}
assert_join_threads([client_thread, server_thread])
- log_string
+ log_ary
end
def start_httpserver(config={}, &block)