Add test related to filter

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-09-14 17:46:40 +09:00
parent dc037c2389
commit a2c0caa357
No known key found for this signature in database
GPG Key ID: F9E3E329A5C5E4A1

View File

@ -177,4 +177,157 @@ class SourceAndOutputTest < ApplicationSystemTestCase
end
end
end
sub_test_case "filter" do
setup do
config = <<-CONFIG.strip_heredoc
<source>
@type dummy
tag debug.*
</source>
<filter debug.*>
@type stdout
</filter>
<match debug.*>
# http://docs.fluentd.org/articles/out_stdout
type stdout
</match>
CONFIG
@daemon.agent.config_write(config)
visit(source_and_output_daemon_setting_path)
end
test "elements" do
assert_equal(first(".filter .card .card-header").text, "stdout (debug.*)")
end
end
sub_test_case "label" do
setup do
@config = <<-CONFIG.strip_heredoc
<source>
@type dummy
tag debug.*
@label @INPUT
</source>
<label @INPUT>
<filter debug.*>
@type grep
<regexp>
key message
pattern /debug.+/
</regexp>
</filter>
<match debug.*>
@type stdout
</match>
</label>
CONFIG
@daemon.agent.config_write(@config)
visit(source_and_output_daemon_setting_path)
end
test "elements under @INPUT" do
assert do
all(".input h5").map(&:text).include?("@INPUT")
end
assert_equal(first(".input .card .card-header").text, "dummy")
assert do
all(".filter h5").map(&:text).include?("@INPUT")
end
assert_equal(first(".filter .card .card-header").text, "grep (debug.*)")
assert do
all(".output h5").map(&:text).include?("@INPUT")
end
assert_equal(first(".output .card .card-header").text, "stdout (debug.*)")
end
test "click delete button" do
assert do
find(".filter .card-header").click
end
page.accept_confirm do
find(".filter .btn", text: I18n.t("terms.destroy")).click
end
within(".filter .empty") do
assert do
has_content?(I18n.t("fluentd.settings.source_and_output.setting_empty"))
end
end
end
test "click edit and cancel" do
config = <<-CONFIG.strip_heredoc
<filter debug.*>
@type grep
<regexp>
key message
pattern /debug.+/
</regexp>
</filter>
CONFIG
new_config = <<-CONFIG.strip_heredoc
<filter debug.*>
@type grep
<regexp>
key message
pattern /debug2.+/
</regexp>
</filter>
CONFIG
assert do
find(".filter .card-header").click
end
find(".filter .btn", text: I18n.t("terms.edit")).click
original_contents = page.evaluate_script(%Q!document.querySelector(".CodeMirror").CodeMirror.getValue()!)
assert_equal(original_contents, config)
page.execute_script(<<-JS)
var cm = document.querySelector('.CodeMirror').CodeMirror;
cm.setValue(#{new_config.to_json});
JS
find(".filter .btn", text: I18n.t("terms.cancel")).click
contents = page.evaluate_script("document.querySelector('.filter pre').textContent")
assert_equal(contents, config)
assert_equal(@daemon.agent.config.strip, @config.strip)
end
test "click edit and save" do
config = <<-CONFIG.strip_heredoc
<filter debug.*>
@type grep
<regexp>
key message
pattern /debug.+/
</regexp>
</filter>
CONFIG
new_config = <<-CONFIG.strip_heredoc
<filter debug.*>
@type grep
<regexp>
key message
pattern /debug2.+/
</regexp>
</filter>
CONFIG
assert do
find(".filter .card-header").click
end
find(".filter .btn", text: I18n.t("terms.edit")).click
original_contents = page.evaluate_script(%Q!document.querySelector(".CodeMirror").CodeMirror.getValue()!)
assert_equal(original_contents, config)
page.execute_script(<<-JS)
var cm = document.querySelector('.CodeMirror').CodeMirror;
cm.setValue(#{new_config.to_json});
JS
find(".filter .btn", text: I18n.t("terms.save")).click
sleep(1)
contents = page.evaluate_script("document.querySelector('.filter pre').textContent")
assert_equal(new_config, contents)
end
end
end