Skip to content

Commit

Permalink
Add a test for Fluent::Log::ConsoleAdapter
Browse files Browse the repository at this point in the history
Signed-off-by: Takuro Ashie <[email protected]>
  • Loading branch information
ashie committed Jan 1, 2023
1 parent 7f4a664 commit 4d141de
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/log/test_console_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require_relative '../helper'

require 'fluent/log'
require 'fluent/log/console_adapter'

class ConsoleAdapterTest < Test::Unit::TestCase
def setup
@timestamp = Time.parse("2023-01-01 15:32:41 +0000")
@timestamp_str = @timestamp.strftime("%Y-%m-%d %H:%M:%S %z")
Timecop.freeze(@timestamp)

@logdev = Fluent::Test::DummyLogDevice.new
@logger = ServerEngine::DaemonLogger.new(@logdev)
@fluent_log = Fluent::Log.new(@logger)
@console_logger = Fluent::Log::ConsoleAdapter.wrap(@fluent_log)
@console_logger.level = :debug
end

def teardown
Timecop.return
end

data(debug: :debug,
info: :info,
warn: :warn,
error: :error,
fatal: :fatal)
def test_one_message(level)
@console_logger.send(level, "message1")
assert_equal(["#{@timestamp_str} [#{level}]: message1\n"],
@logdev.logs)
end
end

0 comments on commit 4d141de

Please sign in to comment.