2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp do
|
2020-04-08 14:13:33 +05:30
|
|
|
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]',
|
2021-01-29 00:20:46 +05:30
|
|
|
'name': 'gitlab test',
|
|
|
|
'int': 42
|
2020-04-08 14:13:33 +05:30
|
|
|
},
|
|
|
|
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
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:time) { Time.now }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:result) { Gitlab::Json.parse(subject) }
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
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]' },
|
2021-01-29 00:20:46 +05:30
|
|
|
{ 'key' => 'name', 'value' => 'gitlab test' },
|
|
|
|
{ 'key' => 'int', 'value' => 42 }
|
2020-04-08 14:13:33 +05:30
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|