Skip to content

Commit

Permalink
tests: fix Hash#inspect format for Ruby HEAD
Browse files Browse the repository at this point in the history
Hash#inspect style was updated at
ruby/ruby@a8a0591

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 <[email protected]>
  • Loading branch information
Watson1978 committed Oct 21, 2024
1 parent a2b935a commit ab7a81d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/config/test_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions test/plugin/test_filter_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_formatter_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/plugin/test_out_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab7a81d

Please sign in to comment.