2019-05-02 00:16:49 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-30 08:30:15 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-05-02 00:16:49 +00:00
|
|
|
describe Gitlab::GraphqlLogger do
|
2019-04-30 08:30:15 +00:00
|
|
|
subject { described_class.new('/dev/null') }
|
2019-05-23 21:29:19 +00:00
|
|
|
|
2019-04-30 08:30:15 +00: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 05:13:06 +00:00
|
|
|
|
|
|
|
context 'logging a GraphQL query' do
|
|
|
|
let(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) }
|
2019-05-23 21:29:19 +00:00
|
|
|
|
2019-05-22 05:13:06 +00:00
|
|
|
it 'logs a query from JSON' do
|
|
|
|
analyzer_memo = {
|
2019-05-23 22:43:47 +00:00
|
|
|
query_string: query,
|
|
|
|
variables: {},
|
|
|
|
complexity: 181,
|
|
|
|
depth: 0,
|
2020-05-13 21:08:55 +00:00
|
|
|
duration_s: 7
|
2019-05-22 05:13:06 +00:00
|
|
|
}
|
2019-05-23 22:43:47 +00:00
|
|
|
|
2019-05-22 05:13:06 +00:00
|
|
|
output = subject.format_message('INFO', now, 'test', analyzer_memo)
|
|
|
|
|
2020-05-01 00:09:59 +00:00
|
|
|
data = Gitlab::Json.parse(output)
|
2019-05-22 05:13:06 +00: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 21:08:55 +00:00
|
|
|
expect(data['duration_s']).to eq(7)
|
2019-05-22 05:13:06 +00:00
|
|
|
end
|
|
|
|
end
|
2019-04-30 08:30:15 +00:00
|
|
|
end
|