From ab7a81de6d229dd95c7865deaa1346019f7bb535 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Mon, 21 Oct 2024 11:37:01 +0900 Subject: [PATCH] tests: fix Hash#inspect format for Ruby HEAD Hash#inspect style was updated at https://github.com/ruby/ruby/commit/a8a059125314a411eaf879a9fbfdc68d6c01a667 Since its changing, fluentd's CI fails with Ruby HEAD. https://github.com/fluent/fluentd/actions/runs/11427054212 This patch will recognize that style changing due to pass the CI tests. Signed-off-by: Shizuo Fujita --- test/config/test_element.rb | 4 ++-- test/plugin/test_filter_stdout.rb | 8 ++++---- test/plugin/test_formatter_hash.rb | 4 ++-- test/plugin/test_out_stdout.rb | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/config/test_element.rb b/test/config/test_element.rb index 1181138724..7bfe925348 100644 --- a/test/config/test_element.rb +++ b/test/config/test_element.rb @@ -282,8 +282,8 @@ def element(name = 'ROOT', arg = '', attrs = {}, elements = [], unused = nil) dump = <<-CONF name:ROOT, arg:, {\"k1\"=>\"v1\"}, [name:test, arg:ext, {\"k2\"=>\"v2\"}, []] CONF - assert_not_equal(e.to_s, e.inspect) - assert_equal(dump.chomp, e.inspect) + assert_not_equal(e.to_s, e.inspect.gsub(' => ', '=>')) + assert_equal(dump.chomp, e.inspect.gsub(' => ', '=>')) end end diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 49f58ef5d6..872c2ccda5 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -86,12 +86,12 @@ def test_output_type_hash d = create_driver(CONFIG + config_element("", "", { "output_type" => "hash" })) etime = event_time("2016-10-07 21:09:31.012345678 UTC") out = capture_log(d) { filter(d, etime, {'test' => 'test'}) } - assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>\"test\"}\n", out + assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>\"test\"}\n", out.gsub(' => ', '=>') # NOTE: Float::NAN is not jsonable, but hash string can output it. d = create_driver(CONFIG + config_element("", "", { "output_type" => "hash" })) out = capture_log(d) { filter(d, etime, {'test' => Float::NAN}) } - assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>NaN}\n", out + assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>NaN}\n", out.gsub(' => ', '=>') end # Use include_time_key to output the message's time @@ -172,7 +172,7 @@ def test_hash d = create_driver(conf) etime = event_time("2016-10-07 21:09:31.012345678 UTC") out = capture_log(d) { filter(d, etime, {'test' => 'test'}) } - assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>\"test\"}\n", out + assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>\"test\"}\n", out.gsub(' => ', '=>') end def test_hash_nan @@ -182,7 +182,7 @@ def test_hash_nan d = create_driver(conf) etime = event_time("2016-10-07 21:09:31.012345678 UTC") out = capture_log(d) { filter(d, etime, {'test' => Float::NAN}) } - assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>NaN}\n", out + assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>NaN}\n", out.gsub(' => ', '=>') end # Use include_time_key to output the message's time diff --git a/test/plugin/test_formatter_hash.rb b/test/plugin/test_formatter_hash.rb index 76eded9c7f..f626f6cf9f 100644 --- a/test/plugin/test_formatter_hash.rb +++ b/test/plugin/test_formatter_hash.rb @@ -26,13 +26,13 @@ def test_format(data) d = create_driver({"newline" => newline_conf}) formatted = d.instance.format(tag, @time, record) - assert_equal(%Q!{"message"=>"awesome", "greeting"=>"hello"}#{newline}!, formatted.encode(Encoding::UTF_8)) + assert_equal(%Q!{"message"=>"awesome", "greeting"=>"hello"}#{newline}!, formatted.gsub(' => ', '=>').encode(Encoding::UTF_8)) end def test_format_without_newline d = create_driver('add_newline' => false) formatted = d.instance.format(tag, @time, record) - assert_equal(%Q!{"message"=>"awesome", "greeting"=>"hello"}!, formatted.encode(Encoding::UTF_8)) + assert_equal(%Q!{"message"=>"awesome", "greeting"=>"hello"}!, formatted.gsub(' => ', '=>').encode(Encoding::UTF_8)) end end diff --git a/test/plugin/test_out_stdout.rb b/test/plugin/test_out_stdout.rb index cb87008213..b7da8a1af2 100644 --- a/test/plugin/test_out_stdout.rb +++ b/test/plugin/test_out_stdout.rb @@ -95,11 +95,11 @@ def create_driver(conf = CONFIG) d.feed(time, {'test' => 'test2'}) end end - assert_equal "#{Time.at(time).localtime.strftime(TIME_FORMAT)} test: {\"test\"=>\"test2\"}\n", out + assert_equal "#{Time.at(time).localtime.strftime(TIME_FORMAT)} test: {\"test\"=>\"test2\"}\n", out.gsub(' => ', '=>') # NOTE: Float::NAN is not jsonable, but hash string can output it. out = capture_log { d.feed('test', time, {'test' => Float::NAN}) } - assert_equal "#{Time.at(time).localtime.strftime(TIME_FORMAT)} test: {\"test\"=>NaN}\n", out + assert_equal "#{Time.at(time).localtime.strftime(TIME_FORMAT)} test: {\"test\"=>NaN}\n", out.gsub(' => ', '=>') end end @@ -171,7 +171,7 @@ def create_driver(conf = CONFIG) end end - assert_equal "#{Time.at(time).localtime.strftime(TIME_FORMAT)} test: {\"test\"=>\"test\"}\n", out + assert_equal "#{Time.at(time).localtime.strftime(TIME_FORMAT)} test: {\"test\"=>\"test\"}\n", out.gsub(' => ', '=>') end end end