mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
b638dd1948
* 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.
93 lines
1.6 KiB
Ruby
93 lines
1.6 KiB
Ruby
require "test_helper"
|
|
|
|
require "puma/app/status"
|
|
require "rack"
|
|
|
|
class TestAppStatus < Minitest::Test
|
|
class FakeServer
|
|
def initialize
|
|
@status = :running
|
|
@backlog = 0
|
|
@running = 0
|
|
end
|
|
|
|
attr_reader :status
|
|
attr_accessor :backlog, :running
|
|
|
|
def stop
|
|
@status = :stop
|
|
end
|
|
|
|
def halt
|
|
@status = :halt
|
|
end
|
|
|
|
def stats
|
|
"{}"
|
|
end
|
|
end
|
|
|
|
def setup
|
|
@server = FakeServer.new
|
|
@app = Puma::App::Status.new(@server)
|
|
@app.auth_token = nil
|
|
end
|
|
|
|
def lint(uri)
|
|
app = Rack::Lint.new @app
|
|
mock_env = Rack::MockRequest.env_for uri
|
|
app.call mock_env
|
|
end
|
|
|
|
def test_bad_token
|
|
@app.auth_token = "abcdef"
|
|
|
|
status, _, _ = lint('/whatever')
|
|
|
|
assert_equal 403, status
|
|
end
|
|
|
|
def test_good_token
|
|
@app.auth_token = "abcdef"
|
|
|
|
status, _, _ = lint('/whatever?token=abcdef')
|
|
|
|
assert_equal 404, status
|
|
end
|
|
|
|
def test_unsupported
|
|
status, _, _ = lint('/not-real')
|
|
|
|
assert_equal 404, status
|
|
end
|
|
|
|
def test_stop
|
|
status, _ , app = lint('/stop')
|
|
|
|
assert_equal :stop, @server.status
|
|
assert_equal 200, status
|
|
assert_equal ['{ "status": "ok" }'], app.enum_for.to_a
|
|
end
|
|
|
|
def test_halt
|
|
status, _ , app = lint('/halt')
|
|
|
|
assert_equal :halt, @server.status
|
|
assert_equal 200, status
|
|
assert_equal ['{ "status": "ok" }'], app.enum_for.to_a
|
|
end
|
|
|
|
def test_stats
|
|
@server.backlog = 1
|
|
@server.running = 9
|
|
status, _ , app = lint('/stats')
|
|
|
|
assert_equal 200, status
|
|
assert_equal ['{}'], app.enum_for.to_a
|
|
end
|
|
|
|
def test_alternate_location
|
|
status, _ , _ = lint('__alternatE_location_/stats')
|
|
assert_equal 200, status
|
|
end
|
|
end
|