Sha256: 7e782324bc808a4203cd5cf3c689a721c9a2a9e33290fd445f7ea6ee325187f3

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8
require_relative "../spec_helper"
require "logstash/plugin"
require "logstash/event"

describe LogStash::Codecs::Fluent do

  let(:properties) { {:name => "foo" } }
  let(:event)      { LogStash::Event.new(properties) }

  it "should register without errors" do
    plugin = LogStash::Plugin.lookup("codec", "fluent").new
    expect { plugin.register }.to_not raise_error
  end

  describe "event encoding" do

    it "should encode as message pack format" do
      subject.on_event do |event, data|
        fields = MessagePack.unpack(data)
        expect(fields[0]).to eq("log")
        expect(fields[2]["name"]).to eq("foo")
      end
      subject.encode(event)
    end

  end

  describe "event decoding" do

    let(:tag)       { "mytag" }
    let(:epochtime) { event.timestamp.to_i }
    let(:data)      { LogStash::Util.normalize(event.to_hash) }
    let(:message) do
      MessagePack.pack([tag, epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)])
    end

    it "should decode without errors" do
      subject.decode(message) do |event|
       expect(event.get("name")).to eq("foo")
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
logstash-codec-fluent-3.0.2-java spec/codecs/fluent_spec.rb
logstash-codec-fluent-3.0.1-java spec/codecs/fluent_spec.rb
logstash-codec-fluent-3.0.0 spec/codecs/fluent_spec.rb