Sha256: 34938a5963812a2994c16df071e3c1afa7d6b2465be8de978b0e9df41c9d1317

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

require "helper"
require "fluent/plugin/filter_dockergelf.rb"

class DockergelfFilterTest < Test::Unit::TestCase
  setup do
    Fluent::Test.setup
  end

  # default configuration for tests
  CONFIG = %[
    param1 value1
    param2 value2
  ]

  def create_driver(conf = CONFIG)
    Fluent::Test::Driver::Filter.new(Fluent::Plugin::DockergelfFilter).configure(conf)
  end

  def filter(config, messages)
    d = create_driver(config)
    d.run(default_tag: "input.access") do
      messages.each do |message|
        d.feed(message)
      end
    end
    d.filtered_records
  end

  # sub_test_case 'configured with invalid configuration' do
  #   test 'empty configuration' do
  #     assert_raise(Fluent::ConfigError) do
  #       create_driver('')
  #     end
  #   end
  #
  #   test 'param1 should reject too short string' do
  #     conf = %[
  #       param1 a
  #     ]
  #     assert_raise(Fluent::ConfigError) do
  #       create_driver(conf)
  #     end
  #   end
  #   # ...
  # end

  sub_test_case 'plugin will add some fields' do
    test 'add hostname to record' do
      conf = CONFIG
      messages = [
          {"message" => "This is test message"}
      ]
      expected = [
          {"message" => "This is test message"}
      ]
      filtered_records = filter(conf, messages)
      assert_equal(expected, filtered_records)
    end
  end

  sub_test_case 'plugin will add some fields' do
    test 'add hostname to record' do
      conf = CONFIG
      messages = [
          { "message" => "This is test message" }
      ]
      expected = [
          { "message" => "This is test message"}
      ]
      filtered_records = filter(conf, messages)
      assert_equal(expected, filtered_records)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fluent-plugin-dockergelf-0.1.5 test/plugin/test_filter_dockergelf.rb
fluent-plugin-dockergelf-0.1.3 test/plugin/test_filter_dockergelf.rb
fluent-plugin-dockergelf-0.1.2 test/plugin/test_filter_dockergelf.rb
fluent-plugin-dockergelf-0.1.1 test/plugin/test_filter_dockergelf.rb