Skip to content

Commit

Permalink
test: add rotation system config test case
Browse files Browse the repository at this point in the history
Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys committed May 10, 2021
1 parent fa20a03 commit 0e7e2bd
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/config/test_system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,48 @@ def parse_text(text)
sc.overwrite_variables(**s.for_system_config)
assert_equal(level, sc.log_level)
end

sub_test_case "log rotation" do
test "unknown rotate_age" do
conf = parse_text(<<-EOS)
<system>
<log>
rotate_age unknown
</log>
</system>
EOS
assert_raise(Fluent::ConfigError.new("rotate_age must be daily, weekly, monthly or number: <unknown>")) do
Fluent::SystemConfig.new(conf)
end
end

test "invalid rotate age number" do
conf = parse_text(<<-EOS)
<system>
<log>
rotate_age 0
</log>
</system>
EOS
assert_raise(Fluent::ConfigError.new("rotate_age must be daily, weekly, monthly or number: <0>")) do
Fluent::SystemConfig.new(conf)
end
end

test "rotate age" do
conf = parse_text(<<-EOS)
<system>
<log>
rotate_age 3
rotate_size 300
</log>
</system>
EOS
s = FakeSupervisor.new
sc = Fluent::SystemConfig.new(conf)
assert_equal(["3", 300],
[sc.log.rotate_age, sc.log.rotate_size])
end
end
end
end
34 changes: 34 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,40 @@ def test_logger_with_rotate_age_and_rotate_size(rotate_age)
assert_equal 10, $log.out.instance_variable_get(:@shift_size)
end

sub_test_case "system log rotation" do
def parse_text(text)
basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
end

def test_override_default_log_rotate
require "tempfile"
Tempfile.open do |file|
config = parse_text(<<-EOS)
<system>
<log>
rotate_age 3
rotate_size 300
</log>
</system>
EOS
file.puts(config)
file.flush
opts = Fluent::Supervisor.default_options.merge(
log_path: "#{TMP_DIR}/test.log", config_path: file.path
)
sv = Fluent::Supervisor.new(opts)

log = sv.instance_variable_get(:@log)
log.init(:standalone, 0)
logger = $log.instance_variable_get(:@logger)

assert_equal(3, logger.instance_variable_get(:@rotate_age))
assert_equal(300, logger.instance_variable_get(:@rotate_size))
end
end
end

def test_inline_config
omit 'this feature is deprecated. see https://github.com/fluent/fluentd/issues/2711'

Expand Down

0 comments on commit 0e7e2bd

Please sign in to comment.