-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathtest_logger_initializer.rb
46 lines (35 loc) · 1.27 KB
/
test_logger_initializer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require_relative 'helper'
require 'fluent/supervisor'
require 'fileutils'
class LoggerInitializerTest < ::Test::Unit::TestCase
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp/logger_initializer#{ENV['TEST_ENV_NUMBER']}")
teardown do
begin
FileUtils.rm_rf(TMP_DIR)
rescue => _
end
end
test 'when path is given' do
path = File.join(TMP_DIR, 'fluent_with_path.log')
assert_false File.exist?(TMP_DIR)
logger = Fluent::Supervisor::LoggerInitializer.new(path, Fluent::Log::LEVEL_DEBUG, nil, nil, {})
mock.proxy(File).chmod(0o777, TMP_DIR).never
assert_nothing_raised do
logger.init(:supervisor, 0)
end
assert_true File.exist?(TMP_DIR)
end
test 'apply_options with log_dir_perm' do
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
path = File.join(TMP_DIR, 'fluent_with_path.log')
assert_false File.exist?(TMP_DIR)
logger = Fluent::Supervisor::LoggerInitializer.new(path, Fluent::Log::LEVEL_DEBUG, nil, nil, {})
mock.proxy(File).chmod(0o777, TMP_DIR).once
assert_nothing_raised do
logger.init(:supervisor, 0)
end
logger.apply_options(log_dir_perm: 0o777)
assert_true File.exist?(TMP_DIR)
assert_equal 0o777, (File.stat(TMP_DIR).mode & 0xFFF)
end
end