diff --git a/app/models/fluentd/agent/common.rb b/app/models/fluentd/agent/common.rb index c101261..a0f752c 100644 --- a/app/models/fluentd/agent/common.rb +++ b/app/models/fluentd/agent/common.rb @@ -76,6 +76,25 @@ class Fluentd end end + def config_merge(content) + if content.start_with?("}) label, sections = parse_label_section(label_content, started) - contents["label:#{label}"] << { label: label, pos: started, sections: sections } + contents["label:#{label}"] << { label: label, pos: started, sections: sections, size: label_content.size } else raise TypeError, "Unknown section: #{started}: #{section_type}" end diff --git a/test/models/fluentd/agent_common_test.rb b/test/models/fluentd/agent_common_test.rb index 7280ddd..3432865 100644 --- a/test/models/fluentd/agent_common_test.rb +++ b/test/models/fluentd/agent_common_test.rb @@ -80,7 +80,7 @@ class Fluentd { pos: 0, content: source_section_content } ], "label:@INPUT" => [ - { label: "@INPUT", pos: 60, sections: sections } + { label: "@INPUT", pos: 60, sections: sections, size: 116 } ] } assert_equal(expected, actual) @@ -157,10 +157,10 @@ class Fluentd { pos: 61, content: source_section_content2 }, ], "label:@INPUT" => [ - { label: "@INPUT", pos: 124, sections: input_sections } + { label: "@INPUT", pos: 124, sections: input_sections, size: 136 } ], "label:@MAIN" => [ - { label: "@MAIN", pos: 260, sections: main_sections } + { label: "@MAIN", pos: 260, sections: main_sections, size: 211 } ] } assert_equal(expected, actual) @@ -186,5 +186,68 @@ class Fluentd assert_equal(fixture_content("config/multi-label.conf"), config) end end + + sub_test_case "#config_merge" do + test "simple" do + stub(@agent).config { fixture_content("config/simple.conf") } + stub(@agent).backup_config + content = <<-CONFIG + + @type stdout + + CONFIG + mock(@agent).config_append(content) + @agent.config_merge(content) + end + + test "simple with label" do + stub(@agent).config { fixture_content("config/simple.conf") } + stub(@agent).backup_config + content = <<-CONFIG + + CONFIG + mock(@agent).config_append(content) + @agent.config_merge(content) + end + + test "append to label" do + stub(@agent).config { fixture_content("config/label.conf") } + stub(@agent).config_file { "tmp/fluent.conf" } + stub(@agent).backup_config + content = <<-CONFIG + + CONFIG + mock(@agent).config_write(<<-CONFIG) + + @type dummy + tag dummy + @label @INPUT + + + + CONFIG + @agent.config_merge(content) + end + end end end