Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/fluent/config/yaml_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ def section_build(name, config, indent: 0, arg: nil)

config.each do |key, val|
if val.is_a?(Array)
val.each do |v|
sb.add_section(section_build(key, v, indent: indent + @base_indent))
if section?(val.first)
val.each do |v|
sb.add_section(section_build(key, v, indent: indent + @base_indent))
end
else
sb.add_line(key, val)
end
elsif val.is_a?(Hash)
harg = val.delete('$arg')
Expand All @@ -164,6 +168,10 @@ def section_build(name, config, indent: 0, arg: nil)

SectionBuilder.new(name, sb, indent, arg)
end

def section?(value)
value.is_a?(Array) or value.is_a?(Hash)
end
end
end
end
Expand Down
149 changes: 149 additions & 0 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,155 @@ def test_check_not_fetchd
10.times { match_conf['type'] }
assert_equal before_size, match_conf.unused.size
end

data(
"One String for $arg" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
buffer:
$arg: tag
$type: memory
flush_mode: immediate
CONF
"Comma-separated String for $arg" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
buffer:
$arg: tag, time
$type: memory
timekey: 1h
flush_mode: immediate
CONF
"One-liner Array for $arg" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
buffer:
$arg: [tag, time]
$type: memory
timekey: 1h
flush_mode: immediate
CONF
"Multi-liner Array for $arg" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
buffer:
$arg:
- tag
- time
$type: memory
timekey: 1h
flush_mode: immediate
CONF
"One String for normal Array option" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
format:
$type: csv
fields: message
CONF
"Comma-separated String for normal Array option" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
inject:
time_key: timestamp
time_type: string
format:
$type: csv
fields: timestamp, message
CONF
"One-liner Array for normal Array option" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
inject:
time_key: timestamp
time_type: string
format:
$type: csv
fields: [timestamp, message]
CONF
"Multi-liner Array for normal Array option" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: stdout
$tag: test.**
inject:
time_key: timestamp
time_type: string
format:
$type: csv
fields:
- timestamp
- message
CONF
"Multiple sections" => <<~CONF,
config:
- source:
$type: sample
tag: test
- match:
$type: copy
$tag: test.**
store:
- $type: relabel
$label: "@foo"
- $type: relabel
$label: "@bar"
- label:
$name: "@foo"
config:
- match:
$type: stdout
$tag: test.**
- label:
$name: "@bar"
config:
- match:
$type: stdout
$tag: test.**
CONF
)
test "Can parse config without error" do |conf|
write_config "#{TMP_DIR}/config.yaml", conf
read_config("#{TMP_DIR}/config.yaml", use_yaml: true)
end
end

def write_config(path, data, encoding: 'utf-8')
Expand Down