Sha256: 588eb9a478ec02b427e70e3d9c83d4cb9f19828de1a32dccd8ef2202d31519f0

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require "spec_helper"

describe ::LogStasher do
  describe "#log_as_json" do
    it "calls the logger with the payload" do
      expect(::LogStasher.logger).to receive(:<<) do |json|
        expect(::JSON.parse(json)).to eq("yolo" => "brolo")
      end

      ::LogStasher.log_as_json(:yolo => :brolo)
    end

    context "with event" do
      it "calls logger with a logstash event" do
        expect(::LogStasher.logger).to receive(:<<) do |json|
          payload = ::JSON.parse(json)

          expect(payload["@timestamp"]).to_not be_nil
          expect(payload["@version"]).to eq("1")
          expect(payload["yolo"]).to eq("brolo")
        end

        ::LogStasher.log_as_json({:yolo => :brolo}, :as_logstash_event => true)
      end
    end

    context "with metadata" do
      before { ::LogStasher.metadata = { :namespace => :cooldude } }
      after { ::LogStasher.metadata = {} }

      it "calls logger with the metadata" do
        expect(::LogStasher.logger).to receive(:<<) do |json|
          expect(::JSON.parse(json)).to eq("yolo" => "brolo", "metadata" => { "namespace" => "cooldude" })
        end

        ::LogStasher.log_as_json(:yolo => :brolo)
      end

      it "does not merge metadata on an array" do
        expect(::LogStasher.logger).to receive(:<<) do |json|
          expect(::JSON.parse(json)).to eq([{ "yolo" => "brolo" }])
        end

        ::LogStasher.log_as_json([{:yolo => :brolo}])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
md-logstasher-1.6.0 spec/lib/logstasher/logstasher_spec.rb
md-logstasher-1.5.0 spec/lib/logstasher/logstasher_spec.rb