summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/grape_logging/formatters/lograge_with_timestamp_spec.rb
blob: f14f0098a1fd51ca0ad54926499f40c8ad4c2793 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp do
  let(:log_entry) do
    {
      status: 200,
      time: {
        total: 758.58,
        db: 77.06,
        view: 681.52
      },
      method: 'PUT',
      path: '/api/v4/projects/1',
      params: {
        'description': '[FILTERED]',
        'name': 'gitlab test',
        'int': 42
      },
      host: 'localhost',
      remote_ip: '127.0.0.1',
      ua: 'curl/7.66.0',
      route: '/api/:version/projects/:id',
      user_id: 1,
      username: 'root',
      queue_duration: 1764.06,
      gitaly_calls: 6,
      gitaly_duration: 20.0,
      correlation_id: 'WMefXn60429'
    }
  end

  let(:time) { Time.now }
  let(:result) { Gitlab::Json.parse(subject) }

  subject { described_class.new.call(:info, time, nil, log_entry) }

  it 'turns the log entry to valid JSON' do
    expect(result['status']).to eq(200)
  end

  it 're-formats the params hash' do
    params = result['params']

    expect(params).to eq(
      [
        { 'key' => 'description', 'value' => '[FILTERED]' },
        { 'key' => 'name', 'value' => 'gitlab test' },
        { 'key' => 'int', 'value' => 42 }
      ])
  end
end