Sha256: 5bc6f5840d3743c9b67ddd4e19be860df69e3da8ec7bad2b845f00f47379a424

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

require 'fluent/test'
require 'fileutils'

class ExecOutputTest < Test::Unit::TestCase
  def setup
    Fluent::Test.setup
    FileUtils.rm_rf(TMP_DIR)
    FileUtils.mkdir_p(TMP_DIR)
  end

  TMP_DIR = File.dirname(__FILE__) + "/../tmp/out_exec#{ENV['TEST_ENV_NUMBER']}"

  CONFIG = %[
    buffer_path #{TMP_DIR}/buffer
    command cat >#{TMP_DIR}/out
    keys time,tag,k1
    tag_key tag
    time_key time
    time_format %Y-%m-%d %H:%M:%S
    localtime
  ]

  def create_driver(conf = CONFIG)
    Fluent::Test::BufferedOutputTestDriver.new(Fluent::ExecOutput).configure(conf)
  end

  def test_configure
    d = create_driver

    assert_equal ["time","tag","k1"], d.instance.keys
    assert_equal "tag", d.instance.tag_key
    assert_equal "time", d.instance.time_key
    assert_equal "%Y-%m-%d %H:%M:%S", d.instance.time_format
    assert_equal true, d.instance.localtime
  end

  def test_format
    d = create_driver

    time = Time.parse("2011-01-02 13:14:15").to_i
    d.emit({"k1"=>"v1","kx"=>"vx"}, time)
    d.emit({"k1"=>"v2","kx"=>"vx"}, time)

    d.expect_format %[2011-01-02 13:14:15\ttest\tv1\n]
    d.expect_format %[2011-01-02 13:14:15\ttest\tv2\n]

    d.run
  end

  def test_write
    d = create_driver

    time = Time.parse("2011-01-02 13:14:15").to_i
    d.emit({"k1"=>"v1","kx"=>"vx"}, time)
    d.emit({"k1"=>"v2","kx"=>"vx"}, time)

    d.run

    expect_path = "#{TMP_DIR}/out"
    assert_equal true, File.exist?(expect_path)

    data = File.read(expect_path)
    expect_data =
      %[2011-01-02 13:14:15\ttest\tv1\n] +
      %[2011-01-02 13:14:15\ttest\tv2\n]
    assert_equal expect_data, data
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fluentd-0.10.44 test/plugin/out_exec.rb
fluentd-0.10.43 test/plugin/out_exec.rb
fluentd-0.10.42 test/plugin/out_exec.rb
fluentd-0.10.41 test/plugin/out_exec.rb
fluentd-0.10.40 test/plugin/out_exec.rb
fluentd-0.10.39 test/plugin/out_exec.rb