mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-12 17:27:09 +02:00
Add specs
This commit is contained in:
parent
f057f27fc5
commit
7eefa05a44
@ -2,6 +2,7 @@ class Fluentd
|
||||
class Agent
|
||||
class Fluentd
|
||||
include Common
|
||||
|
||||
def self.default_options
|
||||
{
|
||||
:pid_file => "/var/run/fluent.pid",
|
||||
@ -21,7 +22,38 @@ class Fluentd
|
||||
|
||||
def start
|
||||
return true if running?
|
||||
actual_start
|
||||
end
|
||||
|
||||
def stop
|
||||
return true unless running?
|
||||
actual_stop
|
||||
end
|
||||
|
||||
def restart
|
||||
return false unless running?
|
||||
actual_restart
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def actual_start
|
||||
spawn("bundle exec fluentd #{options_to_argv}")
|
||||
wait_starting
|
||||
end
|
||||
|
||||
def actual_stop
|
||||
if Process.kill(:TERM, pid)
|
||||
File.unlink(pid_file)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def actual_restart
|
||||
Process.kill(:HUP, pid)
|
||||
end
|
||||
|
||||
def wait_starting
|
||||
begin
|
||||
timeout(wait_process_starting_seconds) do
|
||||
loop do
|
||||
@ -34,19 +66,6 @@ class Fluentd
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def stop
|
||||
return true unless running?
|
||||
if Process.kill(:TERM, pid)
|
||||
File.unlink(pid_file)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def restart
|
||||
return false unless running?
|
||||
Process.kill(:HUP, pid)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,7 @@ class Fluentd
|
||||
class Agent
|
||||
class TdAgent
|
||||
include Common
|
||||
|
||||
def self.default_options
|
||||
{
|
||||
:pid_file => "/var/run/td-agent/td-agent.pid",
|
||||
|
@ -44,6 +44,60 @@ describe Fluentd::Agent do
|
||||
it { should include("-o #{instance.log_file}") }
|
||||
it { should include("--use-v1-config") }
|
||||
end
|
||||
|
||||
describe "#start" do
|
||||
before { instance.stub(:running?).and_return { running } }
|
||||
|
||||
context "running" do
|
||||
let(:running) { true }
|
||||
after { instance.start }
|
||||
|
||||
it { instance.should_not_receive(:actual_start) }
|
||||
end
|
||||
|
||||
context "not running" do
|
||||
let(:running) { false }
|
||||
after { instance.start }
|
||||
|
||||
it { instance.should_receive(:actual_start) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#stop" do
|
||||
before { instance.stub(:running?).and_return { running } }
|
||||
|
||||
context "running" do
|
||||
let(:running) { true }
|
||||
after { instance.stop }
|
||||
|
||||
it { instance.should_receive(:actual_stop) }
|
||||
end
|
||||
|
||||
context "not running" do
|
||||
let(:running) { false }
|
||||
after { instance.stop }
|
||||
|
||||
it { instance.should_not_receive(:actual_stop) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#restart" do
|
||||
before { instance.stub(:running?).and_return { running } }
|
||||
|
||||
context "running" do
|
||||
let(:running) { true }
|
||||
after { instance.restart }
|
||||
|
||||
it { instance.should_receive(:actual_restart) }
|
||||
end
|
||||
|
||||
context "not running" do
|
||||
let(:running) { false }
|
||||
after { instance.restart }
|
||||
|
||||
it { instance.should_not_receive(:actual_restart) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "TdAgent" do
|
||||
|
Loading…
Reference in New Issue
Block a user