From ccb453d557065425c530ddb413219b29ef31647f Mon Sep 17 00:00:00 2001 From: Philippe Weber Date: Sat, 17 May 2014 15:44:54 +0200 Subject: [PATCH] initial spec for pipe input removed logging fixed encoding header closes 1385 --- lib/logstash/inputs/pipe.rb | 2 ++ spec/inputs/pipe.rb | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 spec/inputs/pipe.rb diff --git a/lib/logstash/inputs/pipe.rb b/lib/logstash/inputs/pipe.rb index 143b8ef14..933c60210 100644 --- a/lib/logstash/inputs/pipe.rb +++ b/lib/logstash/inputs/pipe.rb @@ -46,6 +46,8 @@ class LogStash::Inputs::Pipe < LogStash::Inputs::Base queue << event end end + rescue LogStash::ShutdownSignal => e + break rescue Exception => e @logger.error("Exception while running command", :e => e, :backtrace => e.backtrace) end diff --git a/spec/inputs/pipe.rb b/spec/inputs/pipe.rb new file mode 100644 index 000000000..067937b4a --- /dev/null +++ b/spec/inputs/pipe.rb @@ -0,0 +1,60 @@ +# encoding: utf-8 +require "test_utils" +require "tempfile" + +describe "inputs/pipe" do + extend LogStash::RSpec + + describe "echo" do + event_count = 1 + tmp_file = Tempfile.new('logstash-spec-input-pipe') + + config <<-CONFIG + input { + pipe { + command => "echo ☹" + } + } + CONFIG + + input do |pipeline, queue| + Thread.new { pipeline.run } + sleep 0.1 while !pipeline.ready? + + events = event_count.times.collect { queue.pop } + event_count.times do |i| + insist { events[i]["message"] } == "☹" + end + end # input + end + + describe "tail -f" do + event_count = 10 + tmp_file = Tempfile.new('logstash-spec-input-pipe') + + config <<-CONFIG + input { + pipe { + command => "tail -f #{tmp_file.path}" + } + } + CONFIG + + input do |pipeline, queue| + Thread.new { pipeline.run } + sleep 0.1 while !pipeline.ready? + + File.open(tmp_file, "a") do |fd| + event_count.times do |i| + # unicode smiley for testing unicode support! + fd.puts("#{i} ☹") + end + end + events = event_count.times.collect { queue.pop } + event_count.times do |i| + insist { events[i]["message"] } == "#{i} ☹" + end + end # input + end + +end