1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Use Minitest instead of Test::Unit (#1152)

* Bump minitest version.

* Add basic test helper file.

* Use minitest for web server tests.

* Use Minitest for unix socket tests.

* Use Minitest for ThreadPool tests.

* Use Minitest for TCP-Rack tests

* Use Minitest for TCPLogger tests.

* Add missing helper to test helpers.

* Use Minitest for Rack server tests.

* Use Minitest for Rack handler tests.

* Use Minitest for Puma::Server tests.

* Use Minitest for Puma::Server with SSL tests.

* Use Minitest for persisten connections tests.

* Require puma in test_helper file.

* Use minitest for Puma::NullIO tests.

* Remove unnecessary requires on test files.

* Use Minitest for MiniSSL tests.

* Use Minitest for IOBuffer tests.

* Require bundler/setup in Rakefile.

* Use Minitest for HttpParser tests.

* Use Minitest for Puma::Configuration tests.

* Use Minitest for Puma::CLI tests.

* Bump Minitest version for Ruby 2.1 Gemfile.

* Use Minitest for integration tests.

* Use Minitest for Puma::App::Status tests.

* Remove test-unit from Gemfiles.

* Add timeout helper to Minitest::Test.

* Use Minitest for Puma::Binder tests.

* Remove testhelp file.

* Add missing require to Puma::Binder tests.

* Prefer require instead of require_relative.
This commit is contained in:
Francesco Rodriguez 2016-11-22 16:05:49 +01:00 committed by Nate Berkopec
parent e53f9eb2f3
commit b638dd1948
24 changed files with 114 additions and 157 deletions

View file

@ -5,9 +5,8 @@ gem "hoe-git"
gem "hoe-ignore"
gem "rdoc"
gem "rake-compiler"
gem "test-unit", "~> 3.0"
gem "rack", "< 3.0"
gem 'minitest', '~> 5.8'
gem "minitest", "~> 5.9"
gem "jruby-openssl", :platform => "jruby"

View file

@ -1,3 +1,4 @@
require "bundler/setup"
require "hoe"
require "rake/extensiontask"
require "rake/javaextensiontask"

View file

@ -5,9 +5,8 @@ gem "hoe-git"
gem "hoe-ignore"
gem "rdoc"
gem "rake-compiler"
gem "test-unit", "~> 3.0"
gem "rack", "~> 1.6"
gem 'minitest', '~> 5.8'
gem "minitest", '~> 5.9'
gem "jruby-openssl", :platform => "jruby"

View file

@ -1,8 +1,9 @@
require 'test/unit'
require 'rack'
require 'puma/app/status'
require "test_helper"
class TestAppStatus < Test::Unit::TestCase
require "puma/app/status"
require "rack"
class TestAppStatus < Minitest::Test
class FakeServer
def initialize
@status = :running

View file

@ -1,11 +1,10 @@
require "rbconfig"
require 'test/unit'
require 'testhelp'
require "test_helper"
require 'puma/binder'
require 'puma/events'
require "puma/binder"
require "puma/events"
require "puma/puma_http11"
class TestBinder < Test::Unit::TestCase
class TestBinder < Minitest::Test
def setup
@events = Puma::Events.new(STDOUT, STDERR)
@ -13,7 +12,7 @@ class TestBinder < Test::Unit::TestCase
end
def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
omit_on_jruby
skip_on_jruby
@binder.parse(["tcp://localhost:10001"], @events)
@ -21,7 +20,7 @@ class TestBinder < Test::Unit::TestCase
end
def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses
omit_on_jruby
skip_on_jruby
key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__

View file

@ -1,10 +1,8 @@
require "rbconfig"
require 'test/unit'
require 'puma/cli'
require 'tempfile'
require 'yaml'
require "test_helper"
class TestCLI < Test::Unit::TestCase
require "puma/cli"
class TestCLI < Minitest::Test
def setup
@environment = 'production'
@tmp_file = Tempfile.new("puma-test")
@ -168,10 +166,7 @@ class TestCLI < Test::Unit::TestCase
"--state", @tmp_path ]
cli.launcher.write_state
data = nil
assert_nothing_raised do
data = YAML.load_file( @tmp_path )
end
data = YAML.load_file(@tmp_path)
keys_not_stripped = data.keys & Puma::CLI::KEYS_NOT_TO_PERSIST_IN_STATE
assert_empty keys_not_stripped

View file

@ -1,9 +1,8 @@
require 'test/unit'
require "test_helper"
require 'puma'
require 'puma/configuration'
require "puma/configuration"
class TestConfigFile < Test::Unit::TestCase
class TestConfigFile < Minitest::Test
def test_app_from_rackup
conf = Puma::Configuration.new do |c|
c.rackup "test/hello-bind.ru"

View file

@ -1,20 +1,17 @@
# Copyright (c) 2011 Evan Phoenix
# Copyright (c) 2005 Zed A. Shaw
require 'rubygems'
require 'test/unit'
require 'net/http'
require 'digest/sha1'
require 'uri'
require 'stringio'
require 'puma'
require 'puma/detect'
require "bundler/setup"
require "minitest/autorun"
require "minitest/pride"
require "puma"
require "puma/detect"
# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris)
results = []
uris.each do |u|
res = nil
@ -33,7 +30,7 @@ def hit(uris)
end
module TimeoutEveryTestCase
def run(*args)
def run(*)
if !!ENV['CI']
Timeout.timeout(60) { super }
else
@ -41,11 +38,13 @@ module TimeoutEveryTestCase
end
end
end
Test::Unit::TestCase.prepend TimeoutEveryTestCase
module OmitTestsBasedOnRubyEngine
def omit_on_jruby
omit "Omitted on JRuby" if Puma.jruby?
Minitest::Test.prepend TimeoutEveryTestCase
module SkipTestsBasedOnRubyEngine
def skip_on_jruby
skip "Skipped on JRuby" if Puma.jruby?
end
end
Test::Unit::TestCase.prepend OmitTestsBasedOnRubyEngine
Minitest::Test.include SkipTestsBasedOnRubyEngine

View file

@ -1,10 +1,10 @@
require 'testhelp'
require "test_helper"
class Http10ParserTest < Test::Unit::TestCase
include Puma
require "puma/puma_http11"
class Http10ParserTest < Minitest::Test
def test_parse_simple
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
http = "GET / HTTP/1.0\r\n\r\n"
nread = parser.execute(req, http, 0)
@ -17,10 +17,10 @@ class Http10ParserTest < Test::Unit::TestCase
assert_equal '/', req['REQUEST_PATH']
assert_equal 'HTTP/1.0', req['HTTP_VERSION']
assert_equal '/', req['REQUEST_URI']
assert_equal 'GET', req['REQUEST_METHOD']
assert_equal 'GET', req['REQUEST_METHOD']
assert_nil req['FRAGMENT']
assert_nil req['QUERY_STRING']
parser.reset
assert parser.nread == 0, "Number read after reset should be 0"
end

View file

@ -1,14 +1,14 @@
# Copyright (c) 2011 Evan Phoenix
# Copyright (c) 2005 Zed A. Shaw
require 'testhelp'
require "test_helper"
include Puma
require "puma/puma_http11"
class Http11ParserTest < Test::Unit::TestCase
class Http11ParserTest < Minitest::Test
def test_parse_simple
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
http = "GET /?a=1 HTTP/1.1\r\n\r\n"
nread = parser.execute(req, http, 0)
@ -30,7 +30,7 @@ class Http11ParserTest < Test::Unit::TestCase
end
def test_parse_escaping_in_query
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
http = "GET /admin/users?search=%27%%27 HTTP/1.1\r\n\r\n"
nread = parser.execute(req, http, 0)
@ -48,7 +48,7 @@ class Http11ParserTest < Test::Unit::TestCase
end
def test_parse_absolute_uri
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
http = "GET http://192.168.1.96:3000/api/v1/matches/test?1=1 HTTP/1.1\r\n\r\n"
nread = parser.execute(req, http, 0)
@ -72,7 +72,7 @@ class Http11ParserTest < Test::Unit::TestCase
end
def test_parse_dumbfuck_headers
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
should_be_good = "GET / HTTP/1.1\r\naaaaaaaaaaaaa:++++++++++\r\n\r\n"
nread = parser.execute(req, should_be_good, 0)
@ -82,7 +82,7 @@ class Http11ParserTest < Test::Unit::TestCase
end
def test_parse_error
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
bad_http = "GET / SsUTF/1.1"
@ -99,12 +99,12 @@ class Http11ParserTest < Test::Unit::TestCase
end
def test_fragment_in_uri
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
get = "GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n\r\n"
assert_nothing_raised do
parser.execute(req, get, 0)
end
parser.execute(req, get, 0)
assert parser.finished?
assert_equal '/forums/1/topics/2375?page=1', req['REQUEST_URI']
assert_equal 'posts-17408', req['FRAGMENT']
@ -125,7 +125,7 @@ class Http11ParserTest < Test::Unit::TestCase
end
def test_max_uri_path_length
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
# Support URI path length to a max of 2048
@ -145,7 +145,7 @@ class Http11ParserTest < Test::Unit::TestCase
end
def test_horrible_queries
parser = HttpParser.new
parser = Puma::HttpParser.new
# then that large header names are caught
10.times do |c|

View file

@ -1,17 +1,11 @@
require "rbconfig"
require 'test/unit'
require 'socket'
require 'timeout'
require 'net/http'
require 'tempfile'
require "test_helper"
require 'puma/cli'
require 'puma/control_cli'
require 'puma/detect'
require "puma/cli"
require "puma/control_cli"
# These don't run on travis because they're too fragile
class TestIntegration < Test::Unit::TestCase
class TestIntegration < Minitest::Test
def setup
@state_path = "test/test_puma.state"
@bind_path = "test/test_server.sock"
@ -116,7 +110,8 @@ class TestIntegration < Test::Unit::TestCase
end
def test_phased_restart_via_pumactl
omit("Too finicky, fails 50% of the time on CI.")
skip("Too finicky, fails 50% of the time on CI.")
if Puma.jruby? || Puma.windows?
assert true
return

View file

@ -1,7 +1,8 @@
require 'puma/io_buffer'
require 'test/unit'
require "test_helper"
class TestIOBuffer < Test::Unit::TestCase
require "puma/io_buffer"
class TestIOBuffer < Minitest::Test
attr_accessor :iobuf
def setup
self.iobuf = Puma::IOBuffer.new
@ -13,7 +14,7 @@ class TestIOBuffer < Test::Unit::TestCase
end
def test_append_op
iobuf << "abc"
iobuf << "abc"
assert_equal "abc", iobuf.to_s
iobuf << "123"
assert_equal "abc123", iobuf.to_s

View file

@ -1,28 +1,28 @@
require 'test/unit'
require 'puma'
require 'puma/minissl'
require "test_helper"
class TestMiniSSL < Test::Unit::TestCase
require "puma/minissl"
class TestMiniSSL < Minitest::Test
if defined?(JRUBY_VERSION)
def test_raises_with_invalid_keystore_file
ctx = Puma::MiniSSL::Context.new
exception = assert_raise(ArgumentError) { ctx.keystore = "/no/such/keystore" }
exception = assert_raises(ArgumentError) { ctx.keystore = "/no/such/keystore" }
assert_equal("No such keystore file '/no/such/keystore'", exception.message)
end
else
def test_raises_with_invalid_key_file
ctx = Puma::MiniSSL::Context.new
exception = assert_raise(ArgumentError) { ctx.key = "/no/such/key" }
exception = assert_raises(ArgumentError) { ctx.key = "/no/such/key" }
assert_equal("No such key file '/no/such/key'", exception.message)
end
def test_raises_with_invalid_cert_file
ctx = Puma::MiniSSL::Context.new
exception = assert_raise(ArgumentError) { ctx.cert = "/no/such/cert" }
exception = assert_raises(ArgumentError) { ctx.cert = "/no/such/cert" }
assert_equal("No such cert file '/no/such/cert'", exception.message)
end
end

View file

@ -1,7 +1,8 @@
require 'puma/null_io'
require 'test/unit'
require "test_helper"
class TestNullIO < Test::Unit::TestCase
require "puma/null_io"
class TestNullIO < Minitest::Test
attr_accessor :nio
def setup
self.nio = Puma::NullIO.new

View file

@ -1,8 +1,6 @@
require 'puma'
require 'test/unit'
require 'timeout'
require "test_helper"
class TestPersistent < Test::Unit::TestCase
class TestPersistent < Minitest::Test
def setup
@valid_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\n\r\n"
@close_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n"

View file

@ -1,14 +1,6 @@
require "rbconfig"
require 'test/unit'
require 'socket'
require 'openssl'
require "test_helper"
require 'puma/minissl'
require 'puma/server'
require 'net/https'
class TestPumaServer < Test::Unit::TestCase
class TestPumaServer < Minitest::Test
def setup
@port = 0
@ -195,7 +187,7 @@ class TestPumaServer < Test::Unit::TestCase
data = sock.read
assert_not_match(/don't leak me bro/, data)
refute_match(/don't leak me bro/, data)
assert_match(/HTTP\/1.0 500 Internal Server Error/, data)
end
@ -304,7 +296,8 @@ class TestPumaServer < Test::Unit::TestCase
end
def test_timeout_in_data_phase
omit("Hangs too often, TODO: fix")
skip("Hangs too often, TODO: fix")
@server.first_data_timeout = 2
@server.add_tcp_listener @host, @port
@server.run

View file

@ -1,12 +1,6 @@
require "rbconfig"
require 'test/unit'
require 'socket'
require 'openssl'
require "test_helper"
require 'puma/minissl'
require 'puma/server'
require 'net/https'
require "puma/events"
class SSLEventsHelper < ::Puma::Events
attr_accessor :addr, :cert, :error
@ -26,7 +20,7 @@ DISABLE_SSL = begin
false
end
class TestPumaServerSSL < Test::Unit::TestCase
class TestPumaServerSSL < Minitest::Test
def setup
return if DISABLE_SSL
@ -130,7 +124,7 @@ class TestPumaServerSSL < Test::Unit::TestCase
end
# client-side TLS authentication tests
class TestPumaServerSSLClient < Test::Unit::TestCase
class TestPumaServerSSLClient < Minitest::Test
def assert_ssl_client_error_match(error, subject=nil, &blk)
@port = 3212

View file

@ -1,9 +1,8 @@
require 'test/unit'
require 'testhelp'
require 'puma'
require 'rack/handler/puma'
require "test_helper"
class TestPumaUnixSocket < Test::Unit::TestCase
require "rack/handler/puma"
class TestPumaUnixSocket < Minitest::Test
def test_handler
handler = Rack::Handler.get(:puma)
assert_equal Rack::Handler::Puma, handler
@ -12,7 +11,7 @@ class TestPumaUnixSocket < Test::Unit::TestCase
end
end
class TestPathHandler < Test::Unit::TestCase
class TestPathHandler < Minitest::Test
def app
Proc.new {|env| @input = env; [200, {}, ["hello world"]]}
end

View file

@ -1,10 +1,8 @@
require 'test/unit'
require 'puma'
require 'rack/lint'
require 'testhelp'
require 'puma/commonlogger'
require "test_helper"
class TestRackServer < Test::Unit::TestCase
require "rack"
class TestRackServer < Minitest::Test
class ErrorChecker
def initialize(app)

View file

@ -1,10 +1,7 @@
require 'minitest/autorun'
require 'minitest/assertions'
require "test_helper"
require 'puma/tcp_logger'
require 'socket'
require 'puma/server'
require 'puma/events'
require "puma/events"
require "puma/tcp_logger"
class TestTCPLogger < Minitest::Test

View file

@ -1,14 +1,8 @@
require "rbconfig"
require 'test/unit'
require 'socket'
require 'openssl'
require "test_helper"
require 'puma/minissl'
require 'puma/server'
require "puma/events"
require 'net/https'
class TestTCPRack < Test::Unit::TestCase
class TestTCPRack < Minitest::Test
def setup
@port = 3212

View file

@ -1,8 +1,8 @@
require 'test/unit'
require "test_helper"
require 'puma/thread_pool'
require "puma/thread_pool"
class TestThreadPool < Test::Unit::TestCase
class TestThreadPool < Minitest::Test
def teardown
@pool.shutdown if @pool

View file

@ -1,13 +1,9 @@
require "rbconfig"
require 'test/unit'
require 'puma/server'
require 'socket'
require "test_helper"
# UNIX sockets are not recommended on JRuby
# (or Windows)
unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
class TestPumaUnixSocket < Test::Unit::TestCase
class TestPumaUnixSocket < Minitest::Test
App = lambda { |env| [200, {}, ["Works"]] }

View file

@ -1,9 +1,9 @@
# Copyright (c) 2011 Evan Phoenix
# Copyright (c) 2005 Zed A. Shaw
require 'testhelp'
require "test_helper"
include Puma
require "puma/server"
class TestHandler
attr_reader :ran_test
@ -15,14 +15,14 @@ class TestHandler
end
end
class WebServerTest < Test::Unit::TestCase
class WebServerTest < Minitest::Test
def setup
@valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
@tester = TestHandler.new
@server = Server.new @tester, Events.strings
@server = Puma::Server.new @tester, Puma::Events.strings
@server.add_tcp_listener "127.0.0.1", 0
@server.run
@ -86,4 +86,3 @@ class WebServerTest < Test::Unit::TestCase
end
end