Sha256: ffd42c6478e5debab1bb584d9497e9c4f2a2f0d089fb9c137d1446d84a7e9ebe

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'
require 'json'
require_relative '../../lib/logasm/adapters/stdout_json_adapter'

describe Logasm::Adapters::StdoutJsonAdapter do
  let(:debug_level_code) { 0 }
  let(:debug_level) { Logasm::Adapters::LOG_LEVELS[debug_level_code] }
  let(:info_level_code) { 1 }
  let(:info_level) { Logasm::Adapters::LOG_LEVELS[info_level_code] }

  describe '#log' do
    context 'when below threshold' do
      let(:adapter) { described_class.new(debug_level_code, service_name) }
      let(:metadata) { {x: 'y'} }
      let(:event) { {a: 'b', x: 'y'} }
      let(:serialized_event) { JSON.dump(event) }
      let(:service_name) { 'my-service' }
      let(:application_name) { 'my_service' }

      before do
        allow(Logasm::Utils).to receive(:build_event)
          .with(metadata, info_level, application_name)
          .and_return(event)
      end

      it 'sends serialized event to STDOUT' do
        expect(STDOUT).to receive(:puts).with(serialized_event)
        adapter.log(info_level, metadata)
      end
    end

    context 'when above threshold' do
      let(:adapter) { described_class.new(info_level_code, service_name) }
      let(:metadata) { {x: 'y'} }
      let(:service_name) { 'my-service' }

      it 'does not log the event' do
        expect(STDOUT).to_not receive(:puts)
        adapter.log(debug_level, metadata)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
logasm-jruby-1.2.0 spec/adapters/stdout_json_adapter_spec.rb
logasm-1.2.0 spec/adapters/stdout_json_adapter_spec.rb