Sha256: 8b4ccf78a6248e2d4eeeb50992e6ebf07154a631ba1394786673199bfa1f6cd1

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8

require '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
end

Version data entries

1 entries across 1 versions & 1 rubygems

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