fluentd-ui/test/controllers/fluentd/agents_controller_test.rb
Kenji Okimoto a6d31ee20d
Add test/controllers/fluentd/agents_controller_test.rb
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2018-08-01 18:45:04 +09:00

40 lines
1.0 KiB
Ruby

require "test_helper"
class Fluentd
class AgentsControllerTest < ActionDispatch::IntegrationTest
setup do
@log = Object.new
@agent = Object.new
@fluentd = FactoryBot.build(:fluentd)
stub(@agent).log { @log }
stub(@fluentd).agent { @agent }
stub(Fluentd).instance { @fluentd }
user = FactoryBot.build(:user)
post(sessions_path(session: { name: user.name, password: user.password }))
end
data("stop" => "stop",
"start" => "start",
"restart" => "restart",
"reload" => "reload")
test "the action succeed" do |action|
mock(@agent).__send__(action) { true }
put(__send__("#{action}_daemon_agent_path"))
end
data("stop" => "stop",
"start" => "start",
"restart" => "restart",
"reload" => "reload")
test "the action failure" do |action|
mock(@agent).__send__(action) { false }
mock(@log).tail(1) { ["dummylog"] } unless action == "stop"
put(__send__("#{action}_daemon_agent_path"))
end
end
end