spec/inputs/exec_spec.rb in logstash-input-exec-3.1.5 vs spec/inputs/exec_spec.rb in logstash-input-exec-3.2.0

- old
+ new

@@ -1,15 +1,22 @@ # encoding: utf-8 +require "timecop" +require "time" require_relative "../spec_helper" describe LogStash::Inputs::Exec do - it "should register" do - input = LogStash::Plugin.lookup("input", "exec").new("command" => "ls", "interval" => 0) - - # register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present - expect {input.register}.to_not raise_error + context "when register" do + it "should not raise error if config is valid" do + input = LogStash::Plugin.lookup("input", "exec").new("command" => "ls", "interval" => 0) + # register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present + expect {input.register}.to_not raise_error + end + it "should raise error if config is invalid" do + input = LogStash::Plugin.lookup("input", "exec").new("command" => "ls") + expect {input.register}.to raise_error + end end context "when operating normally" do let(:input) { LogStash::Plugin.lookup("input", "exec").new("command" => "ls", "interval" => 0) } let(:queue) { [] } @@ -31,9 +38,33 @@ input.inner_run(queue) expect(queue.size).not_to be_zero end + end + + context "when scheduling" do + let(:input) { LogStash::Plugin.lookup("input", "exec").new("command" => "ls", "schedule" => "* * * * * UTC") } + let(:queue) { [] } + + before do + input.register + end + + it "should properly schedule" do + Timecop.travel(Time.new(2000)) + Timecop.scale(60) + runner = Thread.new do + input.run(queue) + end + sleep 3 + input.stop + runner.kill + runner.join + expect(queue.size).to eq(2) + Timecop.return + end + end context "when interrupting the plugin" do it_behaves_like "an interruptible input plugin" do