summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb
blob: fed9aeba30ced1210a3953702e4889bcd336d3cb (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
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