Skip to content

Commit

Permalink
refactor(tests): Remove redundant umask test cases
Browse files Browse the repository at this point in the history
Signed-off-by: kushynoda <egemen.utku3@gmail.com>
  • Loading branch information
egemenkus committed Feb 10, 2025
1 parent 86367ed commit c5119b2
Showing 1 changed file with 8 additions and 101 deletions.
109 changes: 8 additions & 101 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def test_check_not_fetchd
sub_test_case "yaml config" do
def test_included
write_config "#{TMP_DIR}/config_test_not_fetched.yaml", <<-EOS
system:
umask: "0022"
config:
- source:
$type: dummy
Expand Down Expand Up @@ -197,13 +195,12 @@ def test_included
flush_mode: interval
flush_interval: 1s
EOS
root_conf = read_config("#{TMP_DIR}/config_test_not_fetched.yaml", use_yaml: true)
system_conf = root_conf.elements.find { |e| e.name == "system" }
dummy_source_conf = root_conf.elements.find { |e| e.name == "source" && e['@type'] == "dummy" }
tcp_source_conf = root_conf.elements.find { |e| e.name == "source" && e['@type'] == "tcp" }
root_conf = read_config("#{TMP_DIR}/config_test_not_fetched.yaml", use_yaml: true)
dummy_source_conf = root_conf.elements.first
tcp_source_conf = root_conf.elements[1]
parse_tcp_conf = tcp_source_conf.elements.first
match_conf = root_conf.elements.find { |e| e.name == "match" && e.arg == "tag.*" }
label_conf = root_conf.elements.find { |e| e.name == "label" }
match_conf = root_conf.elements[2]
label_conf = root_conf.elements[3]
fluent_log_conf = label_conf.elements.first
fluent_log_buffer_conf = fluent_log_conf.elements.first

Expand All @@ -225,7 +222,6 @@ def test_included
'memory',
'interval',
'1s',
'0022',
],
[
dummy_source_conf['@type'],
Expand All @@ -244,14 +240,11 @@ def test_included
fluent_log_buffer_conf['@type'],
fluent_log_buffer_conf['flush_mode'],
fluent_log_buffer_conf['flush_interval'],
system_conf['umask'],
])
end

def test_included_glob
write_config "#{TMP_DIR}/config.yaml", <<-EOS
system:
umask: "0022"
config:
- !include "include/*.yaml"
EOS
Expand Down Expand Up @@ -279,11 +272,10 @@ def test_included_glob
flush_interval: 1s
EOS
root_conf = read_config("#{TMP_DIR}/config.yaml", use_yaml: true)
system_conf = root_conf.elements.find { |e| e.name == "system" }
tcp_source_conf = root_conf.elements.find { |e| e.name == "source" && e['@type'] == "tcp" }
dummy_source_conf = root_conf.elements.find { |e| e.name == "source" && e['@type'] == "dummy" }
tcp_source_conf = root_conf.elements.first
dummy_source_conf = root_conf.elements[1]
parse_tcp_conf = tcp_source_conf.elements.first
match_conf = root_conf.elements.find { |e| e.name == "match" && e.arg == "tag.*" }
match_conf = root_conf.elements[2]

assert_equal(
[
Expand All @@ -295,7 +287,6 @@ def test_included_glob
'tag.dummy',
'stdout',
'tag.*',
'0022',
],
[
tcp_source_conf['@type'],
Expand All @@ -306,7 +297,6 @@ def test_included_glob
dummy_source_conf['tag'],
match_conf['@type'],
match_conf.arg,
system_conf['umask'],
])
end

Expand Down Expand Up @@ -353,42 +343,6 @@ def test_check_not_fetchd
10.times { match_conf['type'] }
assert_equal before_size, match_conf.unused.size
end

test 'yaml system config with umask' do
write_config "#{TMP_DIR}/config_test_umask.yaml", <<-EOS
system:
umask: "0022"
config:
- source:
$type: dummy
tag: tag.dummy
- match:
$tag: tag.*
$type: stdout
EOS
conf = read_config("#{TMP_DIR}/config_test_umask.yaml", use_yaml: true)
assert_equal "0022", conf.elements.find { |e| e.name == "system" }["umask"]
end

test 'system config with invalid umask' do
conf = <<-EOC
<system>
umask 0999 # invalid octal
</system>
EOC
conf = Fluent::Config.parse(conf, "(test)", "(test_dir)", true)
assert_equal "0999", conf.elements.find { |e| e.name == "system" }["umask"]
end

test 'system config without umask' do
conf = <<-EOC
<system>
# no umask setting
</system>
EOC
conf = Fluent::Config.parse(conf, "(test)", "(test_dir)", true)
assert_nil conf.elements.find { |e| e.name == "system" }["umask"]
end
end

def write_config(path, data, encoding: 'utf-8')
Expand Down Expand Up @@ -417,52 +371,5 @@ def write_config(path, data, encoding: 'utf-8')
assert_equal('value', c['key'])
assert_equal('value2', c['key2'])
end

test 'system config with umask' do
conf = <<-EOC
<system>
umask 0022
</system>
EOC
conf = Fluent::Config.parse(conf, "(test)", "(test_dir)", true)
ra = Fluent::RootAgent.new(log: $log)
old_umask = File.umask
begin
ra.configure(conf)
assert_equal 0022, File.umask
ensure
File.umask(old_umask)
end
end

test 'system config with invalid umask' do
conf = <<-EOC
<system>
umask 0999 # invalid octal
</system>
EOC
conf = Fluent::Config.parse(conf, "(test)", "(test_dir)", true)
ra = Fluent::RootAgent.new(log: $log)
assert_raise(Fluent::ConfigError) do
ra.configure(conf)
end
end

test 'system config without umask' do
conf = <<-EOC
<system>
# no umask setting
</system>
EOC
conf = Fluent::Config.parse(conf, "(test)", "(test_dir)", true)
ra = Fluent::RootAgent.new(log: $log)
old_umask = File.umask
begin
ra.configure(conf)
assert_equal 0022, File.umask
ensure
File.umask(old_umask)
end
end
end
end

0 comments on commit c5119b2

Please sign in to comment.