Sha256: 68ddff0efff52124c120ad9365967a5ee4c4cabe848e7f1ed924e3f7cf374939

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'helper'
require 'fluent/plugin/filter_record_serializer'
require 'yaml'

exit unless defined?(Fluent::Filter)

class RecordSerializerFilterTest < Test::Unit::TestCase
  def setup
    Fluent::Test.setup
  end

  TAG = 'test.serialize'
  FORMAT = 'json'
  FIELD_NAME = 'payload'

  CONFIG = %[
    type record_modifier
  ]

  YAML_CONFIG = %[
    type record_modifier
    format yaml
  ]

  def create_driver(conf=CONFIG)
    Fluent::Test::FilterTestDriver.new(Fluent::RecordSerializerFilter, TAG).configure(conf)
  end

  def test_configure
    d = create_driver
    assert_equal FORMAT, d.instance.format
    assert_equal FIELD_NAME, d.instance.field_name
  end

  def test_json
    record = {'spam' => 1, 'ham' => 'egg',}
    d = create_driver

    d.run do
      d.emit(record)
    end

    assert_equal [{'tag' => TAG, FIELD_NAME => record.to_json}], d.filtered_as_array.map { |e| e.last }
  end

  def test_yaml
    record = {'spam' => 1, 'ham' => 'egg',}
    d = create_driver YAML_CONFIG

    d.run do
      d.emit(record)
    end

    assert_equal [{'tag' => TAG, FIELD_NAME => record.to_yaml}], d.filtered_as_array.map { |e| e.last }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-record-serializer-0.1.0 test/plugin/test_filter_record_serializer.rb