require "test_helper"
class Fluentd
class TestAgentCommon < ActiveSupport::TestCase
class DummyAgent
include ::Fluentd::Agent::Common
end
setup do
@agent = DummyAgent.new
end
sub_test_case "#parse_config" do
test "empty" do
actual = @agent.__send__(:parse_config, "")
assert_equal({}, actual)
end
test "simple" do
actual = @agent.__send__(:parse_config, fixture_content("config/simple.conf"))
source_section_content = <<-CONFIG.strip_heredoc.chomp
@type dummy
tag dummy
CONFIG
filter_section_content = <<-CONFIG.strip_heredoc.chomp
@type stdout
CONFIG
match_section_content = <<-CONFIG.strip_heredoc.chomp
@type stdout
CONFIG
expected = {
"source" => [
{ pos: 0, content: source_section_content }
],
"filter" => [
{ pos: 44, content: filter_section_content }
],
"match" => [
{ pos: 84, content: match_section_content }
]
}
assert_equal(expected, actual)
end
test "simple label" do
actual = @agent.__send__(:parse_config, fixture_content("config/label.conf"))
source_section_content = <<-CONFIG.strip_heredoc.chomp
@type dummy
tag dummy
@label @INPUT
CONFIG
filter_section_content = <<-CONFIG.chomp
@type stdout
CONFIG
match_section_content = <<-CONFIG.chomp
@type stdout
CONFIG
sections = {
"filter" => [
{ pos: 75, content: filter_section_content}
],
"match" => [
{ pos: 121, content: match_section_content}
]
}
expected = {
"source" => [
{ pos: 0, content: source_section_content }
],
"label:@INPUT" => [
{ pos: 60, sections: sections }
]
}
assert_equal(expected, actual)
end
test "multiple labels" do
actual = @agent.__send__(:parse_config, fixture_content("config/multi-label.conf"))
source_section_content1 = <<-CONFIG.strip_heredoc.chomp
@type dummy
tag dummy1
@label @INPUT
CONFIG
source_section_content2 = <<-CONFIG.strip_heredoc.chomp
@type dummy
tag dummy2
@label @INPUT
CONFIG
filter_section_content = <<-CONFIG.chomp
@type stdout
CONFIG
match_section_content = <<-CONFIG.chomp
@type relabel
@label @MAIN
CONFIG
input_sections = {
"filter" => [
{ pos: 140, content: filter_section_content }
],
"match" => [
{ pos: 187, content: match_section_content }
]
}
filter_secion_content1 = <<-CONFIG.chomp
@type stdout
CONFIG
filter_secion_content2 = <<-CONFIG.chomp
@type stdout
CONFIG
match_secion_content1 = <<-CONFIG.chomp
@type stdout
CONFIG
match_secion_content2 = <<-CONFIG.chomp
@type stdout
CONFIG
main_sections = {
"filter" => [
{ pos: 274, content: filter_secion_content1 },
{ pos: 321, content: filter_secion_content2 }
],
"match" => [
{ pos: 368, content: match_secion_content1 },
{ pos: 413, content: match_secion_content2 }
]
}
expected = {
"source" => [
{ pos: 0, content: source_section_content1 },
{ pos: 61, content: source_section_content2 },
],
"label:@INPUT" => [
{ pos: 124, sections: input_sections }
],
"label:@MAIN" => [
{ pos: 259, sections: main_sections }
]
}
assert_equal(expected, actual)
end
end
end
end