Sha256: 9b74dd9a0dbc14a9a085281b3df3779190bfe9d8ef07822db0debc1706581043

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'
require_relative '../../../lib/logasm/adapters/logstash_adapter/formatter'

describe Logasm::Adapters::LogstashAdapter::Formatter do
  subject(:event) { JSON.parse(formatter.call(severity, time, nil, message)) }

  let(:formatter) { described_class.new(service_name) }
  let(:service_name) { 'test_service' }
  let(:severity) { 'INFO' }
  let(:time) { Time.now }
  let(:message) { {} }

  context 'when service name is present' do
    it 'includes it in the event as application' do
      expect(event['application']).to eq('test_service')
    end
  end

  context 'when service name is not present' do
    let(:service_name) { nil }

    it 'includes does not include the application key' do
      expect(event).to_not have_key('application')
    end
  end

  it 'includes severity as lowercase level' do
    expect(event['level']).to eq('info')
  end

  it 'includes timestamp' do
    expect(event['@timestamp']).to match(/\d{4}.*/)
  end

  it 'includes the host' do
    expect(event['host']).to be_a(String)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logasm-0.2.1 spec/adapters/logstash_adapter/formatter_spec.rb
logasm-0.2.0 spec/adapters/logstash_adapter/formatter_spec.rb