Sha256: baa9e00740462511752c5f60a48598f4f103b6d970eda4321b39a1a875a5d23f

Contents?: true

Size: 1.58 KB

Versions: 8

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe Logasm::Utils do
  describe '.build_event' do
    subject(:event) { described_class.build_event(metadata, level, service_name) }

    let(:service_name) { 'test_service' }
    let(:level)        { 'INFO' }
    let(:metadata)     { {x: 'y'} }

    before do
      allow(Time).to receive(:now) { Time.utc(2015, 10, 11, 23, 10, 21, 123456) }
    end

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

    context 'when service name is in camelcase' do
      let(:service_name) { 'InformationService' }

      it 'includes it in the event as lower snake case' do
        expect(event[:application]).to eq('information_service')
      end
    end

    it 'includes level as a lower case string' do
      expect(event[:level]).to eq('info')
    end

    it 'includes timestamp' do
      expect(event[:@timestamp]).to eq('2015-10-11T23:10:21.123Z')
    end

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

    context 'when @timestamp provided' do
      let(:metadata) { {message: 'test', :@timestamp => 'a timestamp'} }

      it 'overwrites @timestamp' do
        expect(subject[:message]).to eq('test')
        expect(subject[:@timestamp]).to eq('a timestamp')
      end
    end

    context 'when host provided' do
      let(:metadata) { {message: 'test', host: 'xyz'} }

      it 'overwrites host' do
        expect(subject[:message]).to eq('test')
        expect(subject[:host]).to eq('xyz')
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
logasm-0.7.0 spec/utils_spec.rb
logasm-0.5.2 spec/utils_spec.rb
logasm-0.5.0 spec/utils_spec.rb
logasm-0.4.1 spec/utils_spec.rb
logasm-0.4.0 spec/utils_spec.rb
logasm-0.3.0 spec/utils_spec.rb
logasm-0.2.6 spec/utils_spec.rb
logasm-0.2.5 spec/utils_spec.rb