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.7-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.7-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.7-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.16.7 test/plugin_helper/http_server/test_app.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin_helper/http_server/test_app.rb
fluentd-1.16.6-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.6-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.6-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.16.6 test/plugin_helper/http_server/test_app.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin_helper/http_server/test_app.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin_helper/http_server/test_app.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin_helper/http_server/test_app.rb
fluentd-1.17.0-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.17.0-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.17.0-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.17.0 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.5-x64-mingw-ucrt test/plugin_helper/http_server/test_app.rb
fluentd-1.16.5-x86-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.5-x64-mingw32 test/plugin_helper/http_server/test_app.rb
fluentd-1.16.5 test/plugin_helper/http_server/test_app.rb