Sha256: d615ed2b45e1713d16c05673b5eb4e9ce9900f06048f6827d215d3af5f451bed

Contents?: true

Size: 1.62 KB

Versions: 22

Compression:

Stored size: 1.62 KB

Contents

require 'fluent/test'

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

  CONFIG = %[
  ]

  def create_driver(conf = CONFIG)
    Fluent::Test::OutputTestDriver.new(Fluent::StdoutOutput).configure(conf)
  end

  def test_configure
    d = create_driver
    assert_equal :json, d.instance.output_type
  end

  def test_configure_output_type
    d = create_driver(CONFIG + "\noutput_type json")
    assert_equal :json, d.instance.output_type

    d = create_driver(CONFIG + "\noutput_type hash")
    assert_equal :hash, d.instance.output_type

    assert_raise(Fluent::ConfigError) do
      d = create_driver(CONFIG + "\noutput_type foo")
    end
  end

  def test_emit_json
    d = create_driver(CONFIG + "\noutput_type json")
    time = Time.now
    out = capture_log { d.emit({'test' => 'test'}, time) }
    assert_equal "#{time.localtime} test: {\"test\":\"test\"}\n", out

    # NOTE: Float::NAN is not jsonable
    assert_raise(Yajl::EncodeError) { d.emit({'test' => Float::NAN}, time) }
  end

  def test_emit_hash
    d = create_driver(CONFIG + "\noutput_type hash")
    time = Time.now
    out = capture_log { d.emit({'test' => 'test'}, time) }
    assert_equal "#{time.localtime} test: {\"test\"=>\"test\"}\n", out

    # NOTE: Float::NAN is not jsonable, but hash string can output it.
    out = capture_log { d.emit({'test' => Float::NAN}, time) }
    assert_equal "#{time.localtime} test: {\"test\"=>NaN}\n", out
  end

  private

  # Capture the log output of the block given
  def capture_log(&block)
    tmp = $log
    $log = StringIO.new
    yield
    return $log.string
  ensure
    $log = tmp
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
fluentd-0.10.57 test/plugin/test_out_stdout.rb
fluentd-0.10.56 test/plugin/test_out_stdout.rb
fluentd-0.10.55 test/plugin/test_out_stdout.rb
fluentd-0.10.54 test/plugin/test_out_stdout.rb
fluentd-0.12.0.pre.1 test/plugin/test_out_stdout.rb
fluentd-0.10.53 test/plugin/test_out_stdout.rb
fluentd-0.10.52 test/plugin/test_out_stdout.rb
fluentd-0.10.51 test/plugin/test_out_stdout.rb
fluentd-0.10.50 test/plugin/test_out_stdout.rb
fluentd-0.10.49 test/plugin/test_out_stdout.rb
fluentd-0.10.48 test/plugin/test_out_stdout.rb
fluentd-0.10.47 test/plugin/test_out_stdout.rb
fluentd-0.10.46 test/plugin/test_out_stdout.rb
fluentd-0.10.45 test/plugin/out_stdout.rb
fluentd-0.10.44 test/plugin/out_stdout.rb
fluentd-0.10.43 test/plugin/out_stdout.rb
fluentd-0.10.42 test/plugin/out_stdout.rb
fluentd-0.10.41 test/plugin/out_stdout.rb
fluentd-0.10.40 test/plugin/out_stdout.rb
fluentd-0.10.39 test/plugin/out_stdout.rb