Sha256: 453e5224bcce018f6befc9180f51c49b0eaae706e29b21bf2fd60aca9bf1afa2

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

require 'test/unit'
require 'rack'
require 'puma/app/status'

class TestAppStatus < Test::Unit::TestCase
  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
  end

  def setup
    @server = FakeServer.new
    @app = Puma::App::Status.new(@server, @server)
    @app.auth_token = nil
  end

  def lint(env)
    app = Rack::Lint.new @app
    mock_env = Rack::MockRequest.env_for env['PATH_INFO']
    app.call mock_env
  end

  def test_bad_token
    @app.auth_token = "abcdef"

    env = { 'PATH_INFO' => "/whatever" }

    status, _, _ = @app.call env

    assert_equal 403, status
    lint(env)
  end

  def test_good_token
    @app.auth_token = "abcdef"

    env = {
      'PATH_INFO' => "/whatever",
      'QUERY_STRING' => "token=abcdef"
    }

    status, _, _ = @app.call env

    assert_equal 404, status
    lint(env)
  end

  def test_unsupported
    env = { 'PATH_INFO' => "/not-real" }

    status, _, _ = @app.call env

    assert_equal 404, status
    lint(env)
  end

  def test_stop
    env = { 'PATH_INFO' => "/stop" }

    status, _ , body = @app.call env

    assert_equal :stop, @server.status
    assert_equal 200, status
    assert_equal ['{ "status": "ok" }'], body
    lint(env)
  end

  def test_halt
    env = { 'PATH_INFO' => "/halt" }

    status, _ , body = @app.call env

    assert_equal :halt, @server.status
    assert_equal 200, status
    assert_equal ['{ "status": "ok" }'], body
    lint(env)
  end

  def test_stats
    env = { 'PATH_INFO' => "/stats" }

    @server.backlog = 1
    @server.running = 9

    status, _ , body = @app.call env

    assert_equal 200, status
    assert_equal ['{ "backlog": 1, "running": 9 }'], body
    lint(env)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puma-1.4.0-java test/test_app_status.rb
puma-1.4.0 test/test_app_status.rb
puma-1.3.1-java test/test_app_status.rb
puma-1.3.1 test/test_app_status.rb
puma-1.3.0-java test/test_app_status.rb
puma-1.3.0 test/test_app_status.rb