Sha256: 8b1eaaa2e309563a4056db4f48c07bac00f847a958b3d3d5e1b783f08c6a11ce

Contents?: true

Size: 1.19 KB

Versions: 155

Compression:

Stored size: 1.19 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
  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' => 'oj', 'yajl' => 'yajl')
  def test_format(data)
    d = create_driver('json_parser' => data)
    formatted = d.instance.format(tag, @time, record)

    assert_equal("#{JSON.generate(record)}\n", 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)}\n", formatted)
  end
end

Version data entries

155 entries across 155 versions & 2 rubygems

Version Path
fluentd-1.7.2-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.7.2 test/plugin/test_formatter_json.rb
fluentd-1.7.1-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.7.1-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.7.1 test/plugin/test_formatter_json.rb
fluentd-1.7.0-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.7.0-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.7.0 test/plugin/test_formatter_json.rb
fluentd-1.7.0.rc1 test/plugin/test_formatter_json.rb
fluentd-1.6.3-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.6.3-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.6.3 test/plugin/test_formatter_json.rb
fluentd-1.6.2-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.6.2-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.6.2 test/plugin/test_formatter_json.rb
fluentd-1.6.1-x86-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.6.1-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.6.1 test/plugin/test_formatter_json.rb
fluentd-1.6.0-x64-mingw32 test/plugin/test_formatter_json.rb
fluentd-1.6.0-x86-mingw32 test/plugin/test_formatter_json.rb