mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-10 16:27:06 +02:00
Add test/integration/fluentd/setting/histories_test.rb
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
parent
a7247dfbe6
commit
3567a98afc
139
test/integration/fluentd/setting/histories_test.rb
Normal file
139
test/integration/fluentd/setting/histories_test.rb
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class HistoriesTest < ActionDispatch::IntegrationTest
|
||||||
|
include ConfigHistories::DaemonHaveSomeConfigHistories
|
||||||
|
|
||||||
|
setup do
|
||||||
|
login_with(FactoryBot.build(:user))
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_test_case "index" do
|
||||||
|
setup do
|
||||||
|
visit("/daemon/setting/histories")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "show histories#index" do
|
||||||
|
assert do
|
||||||
|
page.has_css?("h1", text: I18n.t("fluentd.settings.histories.index.page_title"))
|
||||||
|
end
|
||||||
|
# links to hisotries#show + 1 table header
|
||||||
|
assert_equal(10, all(".row tr").count)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "go to histories#show" do
|
||||||
|
all(".row tr td a").first.click
|
||||||
|
|
||||||
|
assert do
|
||||||
|
page.has_css?("h1", text: I18n.t("fluentd.settings.histories.show.page_title"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_test_case "show" do
|
||||||
|
setup do
|
||||||
|
@last_backup_file = Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order.first)
|
||||||
|
@new_file = Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_test_case "with diff" do
|
||||||
|
setup do
|
||||||
|
visit("/daemon/setting/histories/#{@last_backup_file.file_id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "show histories#show" do
|
||||||
|
assert do
|
||||||
|
page.has_css?("h1", text: I18n.t("fluentd.settings.histories.show.page_title"))
|
||||||
|
end
|
||||||
|
doc = Nokogiri.HTML(page.source)
|
||||||
|
assert_equal(@last_backup_file.content.strip, doc.search("pre").first.text)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "shows diff between current and target" do
|
||||||
|
within(".diff pre") do
|
||||||
|
[
|
||||||
|
"- @type http",
|
||||||
|
"+ @type forward",
|
||||||
|
"- port 8899",
|
||||||
|
"+ port 24224"
|
||||||
|
].each do |text|
|
||||||
|
assert do
|
||||||
|
has_text?(text)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update config and redirect to setting#show" do
|
||||||
|
click_link(I18n.t("terms.reuse"))
|
||||||
|
|
||||||
|
assert do
|
||||||
|
page.has_css?("h1", text: I18n.t("fluentd.settings.show.page_title"))
|
||||||
|
end
|
||||||
|
assert do
|
||||||
|
page.has_text?(I18n.t("messages.config_successfully_copied", brand: "fluentd") )
|
||||||
|
end
|
||||||
|
assert_equal("/daemon/setting", page.current_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_test_case "without diff" do
|
||||||
|
setup do
|
||||||
|
visit("/daemon/setting/histories/#{@new_file.file_id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "shows no diff message" do
|
||||||
|
assert do
|
||||||
|
page.has_text?(I18n.t("messages.no_diff"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_test_case "configtest" do
|
||||||
|
setup do
|
||||||
|
# To use fluentd_gem for real dry-run checking
|
||||||
|
@daemon = FactoryBot.build(:fluentd, variant: "fluentd_gem")
|
||||||
|
end
|
||||||
|
|
||||||
|
def config_test(config)
|
||||||
|
daemon.agent.config_write config
|
||||||
|
daemon.agent.config_write "# dummy"
|
||||||
|
backup = Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order.first)
|
||||||
|
visit("/daemon/setting/histories/#{backup.file_id}")
|
||||||
|
click_link(I18n.t("terms.configtest"))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "invalid config" do
|
||||||
|
config_test(<<-CONFIG)
|
||||||
|
<source>
|
||||||
|
@type no_such_plugin
|
||||||
|
</source>
|
||||||
|
CONFIG
|
||||||
|
assert do
|
||||||
|
!page.has_css?('.alert-success')
|
||||||
|
end
|
||||||
|
assert do
|
||||||
|
page.has_css?('.alert-danger')
|
||||||
|
end
|
||||||
|
assert do
|
||||||
|
page.has_text?(%Q|Unknown input plugin 'no_such_plugin'|)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "valid config" do
|
||||||
|
config_test(<<-CONFIG)
|
||||||
|
<source>
|
||||||
|
@type syslog
|
||||||
|
tag syslog
|
||||||
|
</source>
|
||||||
|
CONFIG
|
||||||
|
|
||||||
|
assert do
|
||||||
|
page.has_css?('.alert-success')
|
||||||
|
end
|
||||||
|
assert do
|
||||||
|
!page.has_css?('.alert-danger')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -7,7 +7,7 @@ module ConfigHistories
|
|||||||
|
|
||||||
included do
|
included do
|
||||||
def daemon
|
def daemon
|
||||||
@daemon ||= stub_daemon
|
@daemon ||= stub_daemon(variant: "fluentd_gem")
|
||||||
end
|
end
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module StubDaemon
|
module StubDaemon
|
||||||
def stub_daemon(running: false)
|
def stub_daemon(running: false, variant: "td-agent")
|
||||||
daemon = FactoryBot.build(:fluentd, variant: "td-agent")
|
daemon = FactoryBot.build(:fluentd, variant: variant)
|
||||||
stub(Fluentd).instance { daemon }
|
stub(Fluentd).instance { daemon }
|
||||||
any_instance_of(Fluentd::Agent::TdAgent) do |object|
|
any_instance_of(Fluentd::Agent::TdAgent) do |object|
|
||||||
stub(object).detached_command { true }
|
stub(object).detached_command { true }
|
||||||
|
Loading…
Reference in New Issue
Block a user