test/plugin/test_out_file.rb in fluentd-0.10.57 vs test/plugin/test_out_file.rb in fluentd-0.10.58
- old
+ new
@@ -1,5 +1,6 @@
+require_relative '../helper'
require 'fluent/test'
require 'fileutils'
require 'time'
class FileOutputTest < Test::Unit::TestCase
@@ -123,11 +124,11 @@
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"
+ expect_path = "#{TMP_DIR}/out_file_test.20110102_0.log.gz"
assert_equal expect_path, path
check_gzipped_result(path, %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n])
end
@@ -175,17 +176,17 @@
d.emit({"a"=>2}, time)
formatted_lines = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
# FileOutput#write returns path
path = d.run
- assert_equal "#{TMP_DIR}/out_file_test._0.log.gz", path
+ assert_equal "#{TMP_DIR}/out_file_test.20110102_0.log.gz", path
check_gzipped_result(path, formatted_lines)
path = d.run
- assert_equal "#{TMP_DIR}/out_file_test._1.log.gz", path
+ assert_equal "#{TMP_DIR}/out_file_test.20110102_1.log.gz", path
check_gzipped_result(path, formatted_lines)
path = d.run
- assert_equal "#{TMP_DIR}/out_file_test._2.log.gz", path
+ assert_equal "#{TMP_DIR}/out_file_test.20110102_2.log.gz", path
check_gzipped_result(path, formatted_lines)
end
def test_write_with_append
d = create_driver %[
@@ -200,17 +201,17 @@
d.emit({"a"=>2}, time)
formatted_lines = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
# FileOutput#write returns path
path = d.run
- assert_equal "#{TMP_DIR}/out_file_test..log.gz", path
+ assert_equal "#{TMP_DIR}/out_file_test.20110102.log.gz", path
check_gzipped_result(path, formatted_lines)
path = d.run
- assert_equal "#{TMP_DIR}/out_file_test..log.gz", path
+ assert_equal "#{TMP_DIR}/out_file_test.20110102.log.gz", path
check_gzipped_result(path, formatted_lines * 2)
path = d.run
- assert_equal "#{TMP_DIR}/out_file_test..log.gz", path
+ assert_equal "#{TMP_DIR}/out_file_test.20110102.log.gz", path
check_gzipped_result(path, formatted_lines * 3)
end
def test_write_with_symlink
conf = CONFIG + %[
@@ -236,9 +237,62 @@
assert !File.exists?(symlink_path)
assert File.symlink?(symlink_path)
ensure
d.instance.shutdown
FileUtils.rm_rf(symlink_path)
+ end
+ end
+
+ sub_test_case 'path' do
+ test 'normal' do
+ d = create_driver(%[
+ path #{TMP_DIR}/out_file_test
+ time_slice_format %Y-%m-%d-%H
+ utc true
+ ])
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
+ d.emit({"a"=>1}, time)
+ # FileOutput#write returns path
+ path = d.run
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13_0.log", path
+ end
+
+ test 'normal with append' do
+ d = create_driver(%[
+ path #{TMP_DIR}/out_file_test
+ time_slice_format %Y-%m-%d-%H
+ utc true
+ append true
+ ])
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
+ d.emit({"a"=>1}, time)
+ path = d.run
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13.log", path
+ end
+
+ test '*' do
+ d = create_driver(%[
+ path #{TMP_DIR}/out_file_test.*.txt
+ time_slice_format %Y-%m-%d-%H
+ utc true
+ ])
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
+ d.emit({"a"=>1}, time)
+ path = d.run
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13_0.txt", path
+ end
+
+ test '* with append' do
+ d = create_driver(%[
+ path #{TMP_DIR}/out_file_test.*.txt
+ time_slice_format %Y-%m-%d-%H
+ utc true
+ append true
+ ])
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
+ d.emit({"a"=>1}, time)
+ path = d.run
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13.txt", path
end
end
end