Sha256: 962f64f4c0c372f1ab5ca979aff75431fd834fb00bde29544128b6fada84ccd1

Contents?: true

Size: 1.83 KB

Versions: 35

Compression:

Stored size: 1.83 KB

Contents

require 'fluent/test'
require 'fileutils'
require 'time'

class FileOutputTest < 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 = %[
    path #{TMP_DIR}/out_file_test
    compress gz
    utc
  ]

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

  def test_configure
    d = create_driver %[
      path test_path
      compress gz
    ]
    assert_equal 'test_path', d.instance.path
    assert_equal :gz, d.instance.compress
  end

  def test_format
    d = create_driver

    time = Time.parse("2011-01-02 13:14:15 UTC").to_i
    d.emit({"a"=>1}, time)
    d.emit({"a"=>2}, time)

    d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
    d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]

    d.run
  end

  def test_write
    d = create_driver

    time = Time.parse("2011-01-02 13:14:15 UTC").to_i
    d.emit({"a"=>1}, time)
    d.emit({"a"=>2}, time)

    # FileOutput#write returns path
    path = d.run
    expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
    assert_equal expect_path, path

    data = Zlib::GzipReader.open(expect_path) {|f| f.read }
    assert_equal %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] +
                    %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n],
                 data
  end

  def test_write_path_increment
    d = create_driver

    time = Time.parse("2011-01-02 13:14:15 UTC").to_i
    d.emit({"a"=>1}, time)
    d.emit({"a"=>2}, time)

    # FileOutput#write returns path
    path = d.run
    assert_equal "#{TMP_DIR}/out_file_test._0.log.gz", path

    path = d.run
    assert_equal "#{TMP_DIR}/out_file_test._1.log.gz", path

    path = d.run
    assert_equal "#{TMP_DIR}/out_file_test._2.log.gz", path
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
fluentd-0.10.35 test/plugin/out_file.rb
fluentd-0.10.34 test/plugin/out_file.rb
fluentd-0.10.33 test/plugin/out_file.rb
fluentd-0.10.32 test/plugin/out_file.rb
fluentd-0.10.31 test/plugin/out_file.rb
fluentd-0.10.30 test/plugin/out_file.rb
fluentd-0.10.29 test/plugin/out_file.rb
fluentd-0.10.28 test/plugin/out_file.rb
fluentd-0.10.27 test/plugin/out_file.rb
fluentd-0.10.26 test/plugin/out_file.rb
fluentd-0.10.25 test/plugin/out_file.rb
fluentd-0.10.24 test/plugin/out_file.rb
fluentd-0.10.23 test/plugin/out_file.rb
fluentd-0.10.22 test/plugin/out_file.rb
fluentd-0.10.21 test/plugin/out_file.rb
fluentd-0.10.20 test/plugin/out_file.rb
fluentd-0.10.19 test/plugin/out_file.rb
fluentd-0.10.18 test/plugin/out_file.rb
fluentd-0.10.17 test/plugin/out_file.rb
fluentd-0.10.16 test/plugin/out_file.rb