2018-12-05 15:54:40 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'lograge', type: :request do
|
|
|
|
let(:headers) { { 'X-Request-ID' => 'new-correlation-id' } }
|
|
|
|
|
|
|
|
context 'for API requests' do
|
2018-12-17 17:52:17 -05:00
|
|
|
subject { get("/api/v4/endpoint", params: {}, headers: headers) }
|
2018-12-05 15:54:40 -05:00
|
|
|
|
|
|
|
it 'logs to api_json log' do
|
|
|
|
# we assert receiving parameters by grape logger
|
|
|
|
expect_any_instance_of(Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp).to receive(:call)
|
2018-12-06 15:46:31 -05:00
|
|
|
.with(anything, anything, anything, a_hash_including("correlation_id" => "new-correlation-id"))
|
2018-12-05 15:54:40 -05:00
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for Controller requests' do
|
2018-12-17 17:52:17 -05:00
|
|
|
subject { get("/", params: {}, headers: headers) }
|
2018-12-05 15:54:40 -05:00
|
|
|
|
|
|
|
it 'logs to production_json log' do
|
|
|
|
# formatter receives a hash with correlation id
|
|
|
|
expect(Lograge.formatter).to receive(:call)
|
2018-12-06 15:46:31 -05:00
|
|
|
.with(a_hash_including("correlation_id" => "new-correlation-id"))
|
2018-12-05 15:54:40 -05:00
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
# a log file receives a line with correlation id
|
|
|
|
expect(Lograge.logger).to receive(:send)
|
2018-12-06 15:46:31 -05:00
|
|
|
.with(anything, include('"correlation_id":"new-correlation-id"'))
|
2018-12-05 15:54:40 -05:00
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|