Welcome to mirror list, hosted at ThFree Co, Russian Federation.

json_formatter_spec.rb « sidekiq_logging « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a2cb38ec5b1a91f13151b52a191c69c885a1035b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::SidekiqLogging::JSONFormatter do
  let(:hash_input) { { foo: 1, bar: 'test' } }
  let(:message) { 'This is a test' }
  let(:timestamp) { Time.now }

  it 'wraps a Hash' do
    result = subject.call('INFO', timestamp, 'my program', hash_input)

    data = JSON.parse(result)
    expected_output = hash_input.stringify_keys
    expected_output['severity'] = 'INFO'
    expected_output['time'] = timestamp.utc.iso8601(3)

    expect(data).to eq(expected_output)
  end

  it 'wraps a String' do
    result = subject.call('DEBUG', timestamp, 'my string', message)

    data = JSON.parse(result)
    expected_output = {
      severity: 'DEBUG',
      time: timestamp.utc.iso8601(3),
      message: message
    }

    expect(data).to eq(expected_output.stringify_keys)
  end
end