test/plugin/test_out_file.rb in fluentd-0.12.26 vs test/plugin/test_out_file.rb in fluentd-0.12.27

- old
+ new

@@ -18,11 +18,11 @@ compress gz utc ] def create_driver(conf = CONFIG) - Fluent::Test::BufferedOutputTestDriver.new(Fluent::FileOutput).configure(conf) + Fluent::Test::TimeSlicedOutputTestDriver.new(Fluent::FileOutput).configure(conf) end def with_timezone(timezone = 'UTC', &block) old = ENV['TZ'] ENV['TZ'] = timezone @@ -141,96 +141,109 @@ 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.20110102_0.log.gz" - assert_equal expect_path, path + paths = d.run + expect_paths = ["#{TMP_DIR}/out_file_test.20110102_0.log.gz"] + assert_equal expect_paths, paths - check_gzipped_result(path, %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]) + check_gzipped_result(paths[0], %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]) end def test_write_with_format_json d = create_driver [CONFIG, 'format json', 'include_time_key true', 'time_as_epoch'].join("\n") 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 - check_gzipped_result(path, %[#{Yajl.dump({"a" => 1, 'time' => time})}\n] + %[#{Yajl.dump({"a" => 2, 'time' => time})}\n]) + paths = d.run + check_gzipped_result(paths[0], %[#{Yajl.dump({"a" => 1, 'time' => time})}\n] + %[#{Yajl.dump({"a" => 2, 'time' => time})}\n]) end def test_write_with_format_ltsv d = create_driver [CONFIG, 'format ltsv', 'include_time_key true'].join("\n") 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 - check_gzipped_result(path, %[a:1\ttime:2011-01-02T13:14:15Z\n] + %[a:2\ttime:2011-01-02T13:14:15Z\n]) + paths = d.run + check_gzipped_result(paths[0], %[a:1\ttime:2011-01-02T13:14:15Z\n] + %[a:2\ttime:2011-01-02T13:14:15Z\n]) end def test_write_with_format_single_value d = create_driver [CONFIG, 'format single_value', 'message_key a'].join("\n") 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 - check_gzipped_result(path, %[1\n] + %[2\n]) + paths = d.run + check_gzipped_result(paths[0], %[1\n] + %[2\n]) 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) formatted_lines = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n] + write_once = ->(){ + d = create_driver + d.emit({"a"=>1}, time) + d.emit({"a"=>2}, time) + d.run + } + + assert !File.exist?("#{TMP_DIR}/out_file_test.20110102_0.log.gz") + # FileOutput#write returns path - path = d.run - 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.20110102_1.log.gz", path - check_gzipped_result(path, formatted_lines) - path = d.run - assert_equal "#{TMP_DIR}/out_file_test.20110102_2.log.gz", path - check_gzipped_result(path, formatted_lines) + paths = write_once.call + assert_equal ["#{TMP_DIR}/out_file_test.20110102_0.log.gz"], paths + check_gzipped_result(paths[0], formatted_lines) + assert_equal 1, Dir.glob("#{TMP_DIR}/out_file_test.*").size + + paths = write_once.call + assert_equal ["#{TMP_DIR}/out_file_test.20110102_1.log.gz"], paths + check_gzipped_result(paths[0], formatted_lines) + assert_equal 2, Dir.glob("#{TMP_DIR}/out_file_test.*").size + + paths = write_once.call + assert_equal ["#{TMP_DIR}/out_file_test.20110102_2.log.gz"], paths + check_gzipped_result(paths[0], formatted_lines) + assert_equal 3, Dir.glob("#{TMP_DIR}/out_file_test.*").size end def test_write_with_append - d = create_driver %[ - path #{TMP_DIR}/out_file_test - compress gz - utc - append true - ] - time = Time.parse("2011-01-02 13:14:15 UTC").to_i - d.emit({"a"=>1}, time) - 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] + write_once = ->(){ + d = create_driver %[ + path #{TMP_DIR}/out_file_test + compress gz + utc + append true + ] + d.emit({"a"=>1}, time) + d.emit({"a"=>2}, time) + d.run + } + # FileOutput#write returns path - path = d.run - 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.20110102.log.gz", path - check_gzipped_result(path, formatted_lines * 2) - path = d.run - assert_equal "#{TMP_DIR}/out_file_test.20110102.log.gz", path - check_gzipped_result(path, formatted_lines * 3) + paths = write_once.call + assert_equal ["#{TMP_DIR}/out_file_test.20110102.log.gz"], paths + check_gzipped_result(paths[0], formatted_lines) + paths = write_once.call + assert_equal ["#{TMP_DIR}/out_file_test.20110102.log.gz"], paths + check_gzipped_result(paths[0], formatted_lines * 2) + paths = write_once.call + assert_equal ["#{TMP_DIR}/out_file_test.20110102.log.gz"], paths + check_gzipped_result(paths[0], formatted_lines * 3) end def test_write_with_symlink conf = CONFIG + %[ symlink_path #{SYMLINK_PATH} @@ -268,12 +281,12 @@ 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 + paths = d.run + assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13_0.log"], paths end test 'normal with append' do d = create_driver(%[ path #{TMP_DIR}/out_file_test @@ -281,24 +294,24 @@ 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 + paths = d.run + assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13.log"], paths 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 + paths = d.run + assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13_0.txt"], paths end test '* with append' do d = create_driver(%[ path #{TMP_DIR}/out_file_test.*.txt @@ -306,11 +319,11 @@ 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 + paths = d.run + assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13.txt"], paths end end end