Skip to content

Commit

Permalink
Use event_time test helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
okkez committed Jun 24, 2016
1 parent cc7681f commit a2102be
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions test/plugin/test_filter_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def filter(d, time, record)

def test_through_record
d = create_driver
time = Time.now
filtered = filter(d, Fluent::EventTime.from_time(time), {'test' => 'test'})
filtered = filter(d, event_time, {'test' => 'test'})
assert_equal([{'test' => 'test'}], filtered)
end

Expand All @@ -65,42 +64,44 @@ def test_invalid_output_type

def test_output_type_json
d = create_driver(CONFIG + "\noutput_type json")
time = Time.now
out = capture_log(d) { filter(d, Fluent::EventTime.from_time(time), {'test' => 'test'}) }
etime = event_time
time = Time.at(etime.sec)
out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out

# NOTE: Float::NAN is not jsonable
d = create_driver(CONFIG + "\noutput_type json")
flexmock(d.instance.router).should_receive(:emit_error_event)
filter(d, Fluent::EventTime.from_time(time), {'test' => Float::NAN})
filter(d, etime, {'test' => Float::NAN})
end

def test_output_type_hash
d = create_driver(CONFIG + "\noutput_type hash")
time = Time.now
out = capture_log(d) { filter(d, Fluent::EventTime.from_time(time), {'test' => 'test'}) }
etime = event_time
time = Time.at(etime.sec)
out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out

# NOTE: Float::NAN is not jsonable, but hash string can output it.
d = create_driver(CONFIG + "\noutput_type hash")
out = capture_log(d) { filter(d, Fluent::EventTime.from_time(time), {'test' => Float::NAN}) }
out = capture_log(d) { filter(d, etime, {'test' => Float::NAN}) }
assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out
end

# Use include_time_key to output the message's time
def test_include_time_key
d = create_driver(CONFIG + "\noutput_type json\ninclude_time_key true\nutc")
time = Time.now
message_time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
etime = event_time
time = Time.at(etime.sec)
message_time = event_time("2011-01-02 13:14:15 UTC")
out = capture_log(d) { filter(d, message_time, {'test' => 'test'}) }
assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15+00:00\"}\n", out
end

# out_stdout formatter itself can also be replaced
def test_format_json
d = create_driver(CONFIG + "\nformat json")
time = Time.now
out = capture_log(d) { filter(d, Fluent::EventTime.from_time(time), {'test' => 'test'}) }
out = capture_log(d) { filter(d, event_time, {'test' => 'test'}) }
assert_equal "{\"test\":\"test\"}\n", out
end

Expand Down

0 comments on commit a2102be

Please sign in to comment.