Skip to content

Commit 06b7380

Browse files
committed
test_config: add test case
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 0d3f43e commit 06b7380

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ gemspec
44

55
gem 'benchmark'
66

7+
gem 'grpc'
8+
gem 'fluent-plugin-opentelemetry', path: '/home/watson/src/fluent-plugin-opentelemetry'
9+
10+
gem 'fluent-plugin-fluent-package-update-notifier'
11+
gem 'fluent-plugin-obsolete-plugins'
12+
713
local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
814
if File.exist?(local_gemfile)
915
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`

test/test_config.rb

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,118 @@ def write_config(path, data, encoding: 'utf-8')
520520
assert_equal('value', c['key'])
521521
assert_equal('value2', c['key2'])
522522
end
523+
524+
sub_test_case 'on_file_parsed' do
525+
test "calling order on normal configuration files" do
526+
write_config("#{TMP_DIR}/build/common_param.conf", <<~EOS)
527+
flush_interval 5s
528+
total_limit_size 100m
529+
chunk_limit_size 1m
530+
EOS
531+
write_config("#{TMP_DIR}/build/server.conf", <<~EOS)
532+
<server>
533+
host 127.0.0.1
534+
port 24224
535+
</server>
536+
EOS
537+
write_config("#{TMP_DIR}/build/forward.conf", <<~EOS)
538+
<match test.*>
539+
@type forward
540+
541+
@include server.conf
542+
</match>
543+
EOS
544+
write_config("#{TMP_DIR}/build/inline.conf", <<~EOS)
545+
<source>
546+
@type stdout
547+
tag test
548+
</source>
549+
EOS
550+
write_config("#{TMP_DIR}/build/fluent.conf", <<~EOS)
551+
<match sample.*>
552+
@type file
553+
<buffer>
554+
@include common_param.conf
555+
</buffer>
556+
</match>
557+
<match debug.*>
558+
@type stdout
559+
<buffer>
560+
@include common_param.conf
561+
</buffer>
562+
</match>
563+
564+
@include forward.conf
565+
EOS
566+
567+
# parsed_files contains file paths in the order of file parsed
568+
parsed_files = []
569+
Fluent::Config.build(
570+
config_path: "#{TMP_DIR}/build/fluent.conf",
571+
additional_config: "@include inline.conf",
572+
on_file_parsed: ->(path) { parsed_files << path },
573+
)
574+
575+
assert_equal(
576+
[
577+
"#{TMP_DIR}/build/common_param.conf",
578+
"#{TMP_DIR}/build/common_param.conf",
579+
"#{TMP_DIR}/build/server.conf",
580+
"#{TMP_DIR}/build/forward.conf",
581+
"#{TMP_DIR}/build/inline.conf",
582+
"#{TMP_DIR}/build/fluent.conf"
583+
],
584+
parsed_files
585+
)
586+
end
587+
588+
test "calling order on YAML configuration files" do
589+
write_config("#{TMP_DIR}/build/common_buffer.yaml", <<~EOS)
590+
- buffer:
591+
flush_interval: 5s
592+
total_limit_size: 100m
593+
chunk_limit_size: 1m
594+
EOS
595+
write_config("#{TMP_DIR}/build/forward.yaml", <<~EOS)
596+
- match:
597+
$tag: test.*
598+
server:
599+
host: 127.0.0.1
600+
port: 24224
601+
EOS
602+
write_config("#{TMP_DIR}/build/fluent.yaml", <<~EOS)
603+
config:
604+
- match:
605+
$tag: sample.*
606+
$type: file
607+
<<: !include common_buffer.yaml
608+
- match:
609+
$tag: debug.*
610+
$type: stdout
611+
<<: !include common_buffer.yaml
612+
- !include forward.yaml
613+
EOS
614+
615+
# parsed_files contains file paths in the order of file parsed
616+
# `additional_config` does not support YAML config
617+
parsed_files = []
618+
Fluent::Config.build(
619+
config_path: "#{TMP_DIR}/build/fluent.yaml",
620+
type: :yaml,
621+
on_file_parsed: ->(path) { parsed_files << path },
622+
)
623+
624+
assert_equal(
625+
[
626+
"#{TMP_DIR}/build/common_buffer.yaml",
627+
"#{TMP_DIR}/build/common_buffer.yaml",
628+
"#{TMP_DIR}/build/forward.yaml",
629+
"#{TMP_DIR}/build/fluent.yaml"
630+
],
631+
parsed_files
632+
)
633+
end
634+
635+
end
523636
end
524637
end

0 commit comments

Comments
 (0)