Sha256: 1a274596996b731d5effc6d3f4c94458fde8d5ccb635a965524130bace0805b8

Contents?: true

Size: 1.87 KB

Versions: 140

Compression:

Stored size: 1.87 KB

Contents

require_relative '../../helper'
require 'flexmock/test_unit'

begin
  require 'fluent/plugin_helper/http_server/app'
  skip = false
rescue LoadError => _
  skip = true
end

unless skip
  class HttpHelperAppTest < Test::Unit::TestCase
    NULL_LOGGER = Logger.new(nil)

    class DummyRounter
      def initialize(table = {})
        @table = table
      end

      def route!(method, path, _req)
        r = @table.fetch(method).fetch(path)
        [200, {}, r]
      end
    end

    sub_test_case '#call' do
      data(
        'GET request' => 'GET',
        'POST request' => 'POST',
        'DELETE request' => 'DELETE',
        'PUT request' => 'PUT',
        'PATCH request' => 'PATCH',
        'OPTION request' => 'OPTIONS',
        'CONNECT request' => 'CONNECT',
        'TRACE request' => 'TRACE',
      )
      test 'dispatch correct path' do |method|
        r = DummyRounter.new(method.downcase.to_sym => { '/path/' => 'hi' })
        app = Fluent::PluginHelper::HttpServer::App.new(r, NULL_LOGGER)
        m = flexmock('request', method: method, path: '/path/')
        r = app.call(m)
        assert_equal(r.body.read, 'hi')
        assert_equal(r.status, 200)
      end

      test 'dispatch correct path for head' do |method|
        r = DummyRounter.new(head: { '/path/' => 'hi' })
        app = Fluent::PluginHelper::HttpServer::App.new(r, NULL_LOGGER)
        m = flexmock('request', method: method, path: '/path')
        r = app.call(m)
        assert_equal(r.body.read, '')
        assert_equal(r.status, 200)
      end

      test 'if path does not end with `/`' do |method|
        r = DummyRounter.new(head: { '/path/' => 'hi' })
        app = Fluent::PluginHelper::HttpServer::App.new(r, NULL_LOGGER)
        m = flexmock('request', method: method, path: '/path')
        r = app.call(m)
        assert_equal(r.body.read, '')
        assert_equal(r.status, 200)
      end
    end
  end
end

Version data entries

140 entries across 140 versions & 7 rubygems

Version Path
fluentd-1.16.4-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.16.4-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.4-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.4 test/plugin_helper/http_server/test_app.rb
fluentd222-1.16.2-x86_64-linux test/plugin_helper/http_server/test_app.rb
fluentd-1.16.3-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.3-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.3-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.16.3 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.2-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.2-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.2-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.16.2 test/plugin_helper/http_server/test_app.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/fluentd-1.16.1/test/plugin_helper/http_server/test_app.rb
fluentd-1.16.1-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.16.1-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.1-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.1 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.0-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.0-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb