Sha256: 2efef306436b0fd0bce08c065433c16fd94ca182333e99ebb5c996a6f87f3d02

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

require 'test/unit'
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)
  end

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

    status, header, body = @app.call env

    assert_equal 404, status
  end

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

    status, header, body = @app.call env

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

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

    status, header, body = @app.call env

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

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

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

    status, header, body = @app.call env

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

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puma-0.9.1-java test/test_app_status.rb
puma-0.9.1 test/test_app_status.rb
puma-0.9.0-java test/test_app_status.rb
puma-0.9.0 test/test_app_status.rb