test/test_out_s3.rb in fluent-plugin-s3-1.7.2 vs test/test_out_s3.rb in fluent-plugin-s3-1.8.0

- old
+ new

@@ -107,10 +107,22 @@ rescue => e # TODO: replace code with disable lzop command assert(e.is_a?(Fluent::ConfigError)) end + data('level default' => nil, + 'level 1' => 1) + def test_configure_with_mime_type_zstd(level) + conf = CONFIG.clone + conf << "\nstore_as zstd\n" + conf << "\n<compress>\nlevel #{level}\n</compress>\n" if level + d = create_driver(conf) + assert_equal 'zst', d.instance.instance_variable_get(:@compressor).ext + assert_equal 'application/x-zst', d.instance.instance_variable_get(:@compressor).content_type + assert_equal (level || 3), d.instance.instance_variable_get(:@compressor).instance_variable_get(:@compress_config).level + end + def test_configure_with_path_style conf = CONFIG.clone conf << "\nforce_path_style true\n" d = create_driver(conf) assert d.instance.force_path_style @@ -450,9 +462,36 @@ Zlib::GzipReader.open(s3_local_file_path) do |gz| data = gz.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 + FileUtils.rm_f(s3_local_file_path) + end + + def test_write_with_zstd + setup_mocks(true) + s3_local_file_path = "/tmp/s3-test.zst" + + expected_s3path = "log/events/ts=20110102-13/events_0-#{Socket.gethostname}.zst" + + setup_s3_object_mocks(s3_local_file_path: s3_local_file_path, s3path: expected_s3path) + + config = CONFIG_TIME_SLICE + "\nstore_as zstd\n" + d = create_time_sliced_driver(config) + + time = event_time("2011-01-02 13:14:15 UTC") + d.run(default_tag: "test") do + d.feed(time, { "a" => 1 }) + d.feed(time, { "a" => 2 }) + end + + File.open(s3_local_file_path, 'rb') do |file| + compressed_data = file.read + uncompressed_data = Zstd.decompress(compressed_data) + expected_data = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n] + assert_equal expected_data, uncompressed_data end FileUtils.rm_f(s3_local_file_path) end class MockResponse