require 'spec_helper' require 'flydata/command/sender' module Flydata module Command describe Sender do let(:flydata) { double("flydata") } let(:data_port) { double("data_port") } let(:opts) do slop = Sender.slop_start slop.parse(args) slop end subject { Sender.new(opts) } describe '#start' do before(:each) do allow(subject).to receive(:process_exist?).and_return(false) expect(subject).to receive(:wait_until_server_ready) expect(subject).to receive(:wait_until_client_ready) allow(Kernel).to receive(:sleep) allow(subject).to receive(:flydata).and_return(flydata) allow(flydata).to receive(:data_port).and_return(data_port) allow(data_port).to receive(:get).and_return("Wibble") allow_any_instance_of(Flydata::AgentCompatibilityCheck).to receive(:check).and_return(true) expect_any_instance_of(Flydata::Command::Sync).to receive(:try_initial_sync).and_return("Wobble") end context "as daemon" do let(:args) { [] } it "starts fluentd with daemon option" do expect(Kernel).to receive(:system).with( Regexp.new( "bash .+/bin/serverinfo"), :out => [Regexp.new(".+/flydata.log"),'a'], :err => [Regexp.new(".+/flydata.log"),'a']) expect(Kernel).to receive(:system).with( Regexp.new( "ruby `which fluentd` -d .+/flydata.pid -l .+/flydata.log -c .+/flydata.conf -p .+/lib/flydata/fluent-plugins")) subject.start(false) end end context "as regular process" do let(:args) { ["-n"] } it "starts fluentd with no daemon option" do expect(Kernel).to receive(:system).with( Regexp.new( "bash .+/bin/serverinfo"), :out => [Regexp.new(".+/flydata.log"),'a'], :err => [Regexp.new(".+/flydata.log"),'a']) expect(Kernel).to receive(:system).with(Regexp.new( "ruby `which fluentd` -l .+/flydata.log -c .+/flydata.conf -p .+/lib/flydata/fluent-plugins")) subject.start(false) end end context "as regular process with long option" do let(:args) { ["--no-daemon"] } it "starts fluentd with no daemon option" do expect(Kernel).to receive(:system).with( Regexp.new( "bash .+/bin/serverinfo"), :out => [Regexp.new(".+/flydata.log"),'a'], :err => [Regexp.new(".+/flydata.log"),'a']) expect(Kernel).to receive(:system).with(Regexp.new( "ruby `which fluentd` -l .+/flydata.log -c .+/flydata.conf -p .+/lib/flydata/fluent-plugins")) subject.start(false) end end end skip '#stop' skip '#restart' end end end