debian-mirror-gitlab/spec/lib/gitlab/graphql_logger_spec.rb

41 lines
1 KiB
Ruby
Raw Normal View History

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