2019-05-01 20:16:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-30 04:30:15 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::GraphqlLogger do
|
2019-04-30 04:30:15 -04:00
|
|
|
subject { described_class.new('/dev/null') }
|
2019-05-23 17:29:19 -04:00
|
|
|
|
2019-04-30 04:30:15 -04:00
|
|
|
let(:now) { Time.now }
|
|
|
|
|
|
|
|
it 'builds a logger once' do
|
|
|
|
expect(::Logger).to receive(:new).and_call_original
|
|
|
|
|
|
|
|
subject.info('hello world')
|
|
|
|
subject.error('hello again')
|
|
|
|
end
|
2019-05-22 01:13:06 -04:00
|
|
|
|
|
|
|
context 'logging a GraphQL query' do
|
|
|
|
let(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) }
|
2019-05-23 17:29:19 -04:00
|
|
|
|
2019-05-22 01:13:06 -04:00
|
|
|
it 'logs a query from JSON' do
|
|
|
|
analyzer_memo = {
|
2019-05-23 18:43:47 -04:00
|
|
|
query_string: query,
|
|
|
|
variables: {},
|
|
|
|
complexity: 181,
|
|
|
|
depth: 0,
|
2020-05-13 17:08:55 -04:00
|
|
|
duration_s: 7
|
2019-05-22 01:13:06 -04:00
|
|
|
}
|
2019-05-23 18:43:47 -04:00
|
|
|
|
2019-05-22 01:13:06 -04:00
|
|
|
output = subject.format_message('INFO', now, 'test', analyzer_memo)
|
|
|
|
|
2020-04-30 20:09:59 -04:00
|
|
|
data = Gitlab::Json.parse(output)
|
2019-05-22 01:13:06 -04:00
|
|
|
expect(data['severity']).to eq('INFO')
|
|
|
|
expect(data['time']).to eq(now.utc.iso8601(3))
|
|
|
|
expect(data['complexity']).to eq(181)
|
|
|
|
expect(data['variables']).to eq({})
|
|
|
|
expect(data['depth']).to eq(0)
|
2020-05-13 17:08:55 -04:00
|
|
|
expect(data['duration_s']).to eq(7)
|
2019-05-22 01:13:06 -04:00
|
|
|
end
|
|
|
|
end
|
2019-04-30 04:30:15 -04:00
|
|
|
end
|