Sha256: 7288bf4e4d62348a7cd7d46026b96ef7d33683e019d7df1c872e41a6cd4b8049

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'
require_relative '../../lib/logasm/adapters/rabbitmq_adapter'

describe Logasm::Adapters::RabbitmqAdapter do
  let(:adapter) do
    described_class.new(log_level, 'TestService', {
      host: 'localhost', user: 'guest', pass: 'guest', port: '5672'
    })
  end
  let(:freddy) { adapter.freddy }

  before do
    allow(Freddy).to receive(:build) { FreddyMock.new }
  end

  describe '#log' do
    context 'when logging a message' do
      let(:log_level) { 0 }

      it 'delegates to freddy' do
        adapter.log :info, message: 'test'

        expect(freddy.deliveries.size).to eq(1)

        queue, event = freddy.deliveries[0]
        expect(queue).to eq('logstash-queue')
        expect(event[:message]).to eq('test')
        expect(event[:application]).to eq('test_service')
        expect(event[:level]).to eq('info')
        expect(event[:host]).to be_a(String)
        expect(event[:@timestamp]).to match(/\d{4}-\d{2}-\d{2}T.*/)
      end
    end

    context 'when log level is lower than threshold' do
      let(:log_level) { 3 }

      it 'does not delegate to freddy' do
        expect(freddy).not_to receive(:deliver)

        adapter.log :info, message: 'test', a: 'b'
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logasm-0.5.0 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.4.1 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.4.0 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.3.0 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.2.6 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.2.5 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.2.4 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.2.3 spec/adapters/rabbitmq_adapter_spec.rb
logasm-0.2.2 spec/adapters/rabbitmq_adapter_spec.rb