2019-07-16 18:53:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-12 15:16:55 -04:00
|
|
|
require_relative "helper"
|
2011-12-05 12:01:19 -05:00
|
|
|
|
2016-11-22 10:05:49 -05:00
|
|
|
require "puma/app/status"
|
|
|
|
require "rack"
|
|
|
|
|
|
|
|
class TestAppStatus < Minitest::Test
|
2019-07-16 18:53:28 -04:00
|
|
|
parallelize_me!
|
|
|
|
|
2011-12-05 12:01:19 -05:00
|
|
|
class FakeServer
|
|
|
|
def initialize
|
|
|
|
@status = :running
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :status
|
|
|
|
|
|
|
|
def stop
|
|
|
|
@status = :stop
|
|
|
|
end
|
|
|
|
|
|
|
|
def halt
|
|
|
|
@status = :halt
|
|
|
|
end
|
2013-07-05 19:08:13 -04:00
|
|
|
|
|
|
|
def stats
|
|
|
|
"{}"
|
|
|
|
end
|
2011-12-05 12:01:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@server = FakeServer.new
|
2013-07-05 19:08:13 -04:00
|
|
|
@app = Puma::App::Status.new(@server)
|
2011-12-06 19:22:02 -05:00
|
|
|
end
|
|
|
|
|
2012-06-29 20:37:05 -04:00
|
|
|
def lint(uri)
|
2012-04-29 15:18:21 -04:00
|
|
|
app = Rack::Lint.new @app
|
2012-06-29 20:37:05 -04:00
|
|
|
mock_env = Rack::MockRequest.env_for uri
|
2012-04-29 15:18:21 -04:00
|
|
|
app.call mock_env
|
|
|
|
end
|
|
|
|
|
2011-12-06 19:22:02 -05:00
|
|
|
def test_bad_token
|
2019-09-20 06:45:56 -04:00
|
|
|
@app.instance_variable_set(:@auth_token, "abcdef")
|
2011-12-06 19:22:02 -05:00
|
|
|
|
2012-06-29 20:37:05 -04:00
|
|
|
status, _, _ = lint('/whatever')
|
2011-12-06 19:22:02 -05:00
|
|
|
|
|
|
|
assert_equal 403, status
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_good_token
|
2019-09-20 06:45:56 -04:00
|
|
|
@app.instance_variable_set(:@auth_token, "abcdef")
|
2011-12-06 19:22:02 -05:00
|
|
|
|
2012-06-29 20:37:05 -04:00
|
|
|
status, _, _ = lint('/whatever?token=abcdef')
|
2011-12-06 19:22:02 -05:00
|
|
|
|
|
|
|
assert_equal 404, status
|
2011-12-05 12:01:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_unsupported
|
2012-06-29 20:37:05 -04:00
|
|
|
status, _, _ = lint('/not-real')
|
2011-12-05 12:01:19 -05:00
|
|
|
|
|
|
|
assert_equal 404, status
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_stop
|
2012-06-29 20:37:05 -04:00
|
|
|
status, _ , app = lint('/stop')
|
2011-12-05 12:01:19 -05:00
|
|
|
|
|
|
|
assert_equal :stop, @server.status
|
|
|
|
assert_equal 200, status
|
2012-06-29 20:37:05 -04:00
|
|
|
assert_equal ['{ "status": "ok" }'], app.enum_for.to_a
|
2011-12-05 12:01:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_halt
|
2012-06-29 20:37:05 -04:00
|
|
|
status, _ , app = lint('/halt')
|
2011-12-05 12:01:19 -05:00
|
|
|
|
|
|
|
assert_equal :halt, @server.status
|
|
|
|
assert_equal 200, status
|
2012-06-29 20:37:05 -04:00
|
|
|
assert_equal ['{ "status": "ok" }'], app.enum_for.to_a
|
2011-12-05 12:01:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_stats
|
2012-06-29 20:37:05 -04:00
|
|
|
status, _ , app = lint('/stats')
|
2011-12-05 12:01:19 -05:00
|
|
|
|
|
|
|
assert_equal 200, status
|
2013-07-05 19:08:13 -04:00
|
|
|
assert_equal ['{}'], app.enum_for.to_a
|
2011-12-05 12:01:19 -05:00
|
|
|
end
|
2012-10-03 21:16:31 -04:00
|
|
|
|
|
|
|
def test_alternate_location
|
2013-06-18 02:07:17 -04:00
|
|
|
status, _ , _ = lint('__alternatE_location_/stats')
|
2012-10-03 21:16:31 -04:00
|
|
|
assert_equal 200, status
|
|
|
|
end
|
2011-12-05 12:01:19 -05:00
|
|
|
end
|