Sha256: eff8476c5e2349ba9c25ed4dbd292d8b79b88c761ceb0b4eb1c862582cb46d41

Contents?: true

Size: 1.59 KB

Versions: 116

Compression:

Stored size: 1.59 KB

Contents

require_relative '../helper'
require 'json'
require 'fluent/test/driver/formatter'
require 'fluent/plugin/formatter_json'

class JsonFormatterTest < ::Test::Unit::TestCase

  def setup
    @time = event_time
    @default_newline = if Fluent.windows?
                         "\r\n"
                       else
                         "\n"
                       end
  end

  def create_driver(conf = "")
    Fluent::Test::Driver::Formatter.new(Fluent::Plugin::JSONFormatter).configure(conf)
  end

  def tag
    "tag"
  end

  def record
    {'message' => 'awesome'}
  end

  def symbolic_record
    {:message => :awesome}
  end

  data('oj with LF' => ['oj', "lf", "\n"],
       'oj with CRLF' => ['oj', "crlf", "\r\n"],
       'yajl with LF' => ['yajl', "lf", "\n"],
       'yajl with CRLF' => ['yajl', "crlf", "\r\n"]
      )
  def test_format(data)
    parser, newline_conf, newline = data
    d = create_driver('json_parser' => parser, 'newline' => newline_conf)
    formatted = d.instance.format(tag, @time, record)

    assert_equal("#{JSON.generate(record)}#{newline}", formatted)
  end

  data('oj' => 'oj', 'yajl' => 'yajl')
  def test_format_without_nl(data)
    d = create_driver('json_parser' => data, 'add_newline' => false)
    formatted = d.instance.format(tag, @time, record)

    assert_equal(JSON.generate(record), formatted)
  end

  data('oj' => 'oj', 'yajl' => 'yajl')
  def test_format_with_symbolic_record(data)
    d = create_driver('json_parser' => data)
    formatted = d.instance.format(tag, @time, symbolic_record)

    assert_equal("#{JSON.generate(record)}#{@default_newline}", formatted)
  end
end

Version data entries

116 entries across 116 versions & 7 rubygems

Version Path
fluentd-1.16.7-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.16.7-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.16.7-x64-mingw-ucrt test/plugin/test_formatter_json.rb
fluentd-1.16.7 test/plugin/test_formatter_json.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_formatter_json.rb
fluentd-1.16.6-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.16.6-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.16.6-x64-mingw-ucrt test/plugin/test_formatter_json.rb
fluentd-1.16.6 test/plugin/test_formatter_json.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_formatter_json.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_formatter_json.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_formatter_json.rb
fluentd-1.17.0-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.17.0-x64-mingw-ucrt test/plugin/test_formatter_json.rb
fluentd-1.17.0-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.17.0 test/plugin/test_formatter_json.rb
fluentd-1.16.5-x64-mingw-ucrt test/plugin/test_formatter_json.rb
fluentd-1.16.5-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.16.5-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.16.5 test/plugin/test_formatter_json.rb