- add more test coverage for the plain codec; promote it to milestone 3.

This commit is contained in:
Jordan Sissel 2013-06-17 10:44:33 -07:00
parent 0e4410a1f0
commit 7c39c85a94
2 changed files with 15 additions and 9 deletions

View file

@ -3,11 +3,10 @@ require "logstash/codecs/base"
# This is the base class for logstash codecs.
class LogStash::Codecs::Plain < LogStash::Codecs::Base
config_name "plain"
milestone 3
milestone 1
# TODO(sissel): Document.
config :format, :validate => :string, :default => nil
# Set the desired text format for encoding.
config :format, :validate => :string
# The character encoding used in this input. Examples include "UTF-8"
# and "cp1252"
@ -30,7 +29,7 @@ class LogStash::Codecs::Plain < LogStash::Codecs::Base
public
def encode(data)
if data.is_a? LogStash::Event and !@format.nil?
if data.is_a? LogStash::Event and @format
@on_event.call(data.sprintf(@format))
else
@on_event.call(data.to_s)

View file

@ -3,10 +3,6 @@ require "logstash/event"
require "insist"
describe LogStash::Codecs::Plain do
subject do
next LogStash::Codecs::Plain.new
end
context "#decode" do
it "should return a valid event" do
subject.decode("Testing decoding.") do |event|
@ -24,5 +20,16 @@ describe LogStash::Codecs::Plain do
end
subject.encode(event)
end
it "should respect the format setting" do
format = "%{[hello]} %{[something][fancy]}"
codec = LogStash::Codecs::Plain.new("format" => format)
event = LogStash::Event.new("hello" => "world", "something" => { "fancy" => 123 })
codec.on_event do |data|
insist { data } == event.sprintf(format)
end
codec.encode(event)
end
end
end