Sha256: a8dde210389e6152b63fc832b8c5f7f5884a71ea90d9b899fd97fadf23a57557

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

require "logstash/devutils/rspec/spec_helper"
require "logstash/codecs/line"
require "logstash/event"

describe LogStash::Codecs::Line do
  subject do
    next LogStash::Codecs::Line.new
  end

  context "#encode" do
    let (:event) {LogStash::Event.new({"message" => "hello world", "host" => "test"})}

    it "should return a default date formatted line" do
      expect(subject).to receive(:on_event).once.and_call_original
      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
      expect(subject).to receive(:on_event).once.and_call_original
      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

  context "#flush" do
    it "should convert charsets" do
      garbage = [0xD0].pack("C")
      subject.decode(garbage) do |e|
        fail "Should not get here."
      end
      count = 0
      subject.flush do |event|
        count += 1
        insist { event["message"].encoding } == Encoding::UTF_8
      end
      insist { count } == 1
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-codec-line-0.1.2 spec/codecs/line_spec.rb
logstash-codec-line-0.1.1 spec/codecs/line_spec.rb