Sha256: 05b7795f6f23d02239b493ef288ff1f75c55541913bd2f3779ace77be36ad585

Contents?: true

Size: 1.57 KB

Versions: 33

Compression:

Stored size: 1.57 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"

  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

33 entries across 33 versions & 1 rubygems

Version Path
fluentd-0.10.38 test/plugin/out_exec.rb
fluentd-0.10.37 test/plugin/out_exec.rb
fluentd-0.10.36 test/plugin/out_exec.rb
fluentd-0.10.35 test/plugin/out_exec.rb
fluentd-0.10.34 test/plugin/out_exec.rb
fluentd-0.10.33 test/plugin/out_exec.rb
fluentd-0.10.32 test/plugin/out_exec.rb
fluentd-0.10.31 test/plugin/out_exec.rb
fluentd-0.10.30 test/plugin/out_exec.rb
fluentd-0.10.29 test/plugin/out_exec.rb
fluentd-0.10.28 test/plugin/out_exec.rb
fluentd-0.10.27 test/plugin/out_exec.rb
fluentd-0.10.26 test/plugin/out_exec.rb
fluentd-0.10.25 test/plugin/out_exec.rb
fluentd-0.10.24 test/plugin/out_exec.rb
fluentd-0.10.23 test/plugin/out_exec.rb
fluentd-0.10.22 test/plugin/out_exec.rb
fluentd-0.10.21 test/plugin/out_exec.rb
fluentd-0.10.20 test/plugin/out_exec.rb
fluentd-0.10.19 test/plugin/out_exec.rb