test/integration/logger_test.rb in filum-2.0.0 vs test/integration/logger_test.rb in filum-2.1.0
- old
+ new
@@ -1,53 +1,17 @@
-require File.expand_path('../../test_helper', __FILE__)
+require_relative 'integration_test_base'
module Filum
- class Worker
- def self.process
- Filum.logger.info "Processing"
- end
- end
+ class LoggerTest < Minitest::Test
+ include IntegrationTestBase
+ protected
- class LoggerTest < IntegrationTest
- def test_one_logline
- test_thread = Thread.new do
- Filum.logger.context_id = "123456"
- Worker.process
- end
- test_thread.join
- assert_logged(/\[123456\]/)
+ def setup
+ super
+ Filum.setup("/tmp/log/filum_test_#{Time.now.to_i}.log")
end
- def test_multiple_threads
- test_thread1 = Thread.new do
- Filum.logger.context_id = "23456a"
- Worker.process
- end
- test_thread2 = Thread.new do
- Filum.logger.context_id = "34567a"
- Worker.process
- end
- test_thread1.join
- test_thread2.join
- assert_logged(/\[23456a\]/)
- assert_logged(/\[34567a\]/)
- end
-
- def test_info_string_is_correct
- random_string = [*'a'..'z'].sample(10).join
- Filum.logger.info "Foobar #{random_string}"
- assert_logged(/Foobar #{random_string}$/)
- end
-
- def test_caller_line_is_correct
- expected_file = 'logger_test.rb'
- expected_line = __LINE__+1
- Filum.logger.info "Foobar"
- assert_logged(/#{expected_file}:#{expected_line}/)
- end
-
- private
def assert_logged(regex)
assert File.readlines(Filum.logger.logfile).grep(regex).size == 1
end
end
end