Line codec was using an undefined variable which casued it to throw and exception.

Fixed and added tests for line codes

Closes #1451
This commit is contained in:
Suyog Rao 2014-06-18 15:18:54 -07:00
parent 65af91d015
commit 393a961805
2 changed files with 52 additions and 1 deletions

View file

@ -48,7 +48,7 @@ class LogStash::Codecs::Line < LogStash::Codecs::Base
public
def encode(event)
if data.is_a? LogStash::Event and @format
if event.is_a? LogStash::Event and @format
@on_event.call(event.sprintf(@format) + NL)
else
@on_event.call(event.to_s + NL)

51
spec/codecs/line.rb Normal file
View file

@ -0,0 +1,51 @@
# encoding: utf-8
require "logstash/codecs/line"
require "logstash/event"
describe LogStash::Codecs::Line do
subject do
next LogStash::Codecs::Line.new
end
context "#encode" do
event = LogStash::Event.new({"message" => "hello world", "host" => "test"})
it "should return a default date formatted line" do
subject.on_event do |d|
insist {d} == event.to_s + "\n"
end
subject.encode(event)
end
it "should respect the supplied format" do
format = "%{host}"
subject.format = format
subject.on_event do |d|
insist {d} == event.sprintf(format) + "\n"
end
subject.encode(event)
end
end
context "#decode" do
it "should return an event from an ascii string" do
decoded = false
subject.decode("hello world\n") do |e|
decoded = true
insist { e.is_a?(LogStash::Event) }
insist { e["message"] } == "hello world"
end
insist { decoded } == true
end
it "should return an event from a valid utf-8 string" do
subject.decode("München\n") do |e|
insist { e.is_a?(LogStash::Event) }
insist { e["message"] } == "München"
end
end
end
end