Sha256: 6845c908164ca9359bd2dec75310d1fa62cb3a0034c1269fcc0257c70dbcf264

Contents?: true

Size: 967 Bytes

Versions: 4

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

require 'minitest/autorun'
require 'json'
require_relative '../lib/twiglet/formatter'
require_relative '../lib/twiglet/validator'

describe Twiglet::Formatter do
  before do
    @now = -> { Time.utc(2020, 5, 11, 15, 1, 1) }
    @formatter = Twiglet::Formatter.new('petshop', now: @now, validator: Twiglet::Validator.new({}))
  end

  it 'initializes an instance of a Ruby Logger Formatter' do
    assert @formatter.is_a?(::Logger::Formatter)
  end

  it 'returns a formatted log from a string message' do
    msg = @formatter.call('warn', nil, nil, 'shop is running low on dog food')
    expected_log = {
      "ecs" => {
        "version" => '1.5.0'
      },
      "@timestamp" => '2020-05-11T15:01:01.000Z',
      "service" => {
        "name" => 'petshop'
      },
      "log" => {
        "level" => 'warn'
      },
      "message" => 'shop is running low on dog food'
    }
    assert_equal JSON.parse(msg), expected_log
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twiglet-3.1.3 test/formatter_test.rb
twiglet-3.1.2 test/formatter_test.rb
twiglet-3.1.1 test/formatter_test.rb
twiglet-3.1.0 test/formatter_test.rb