diff options
author | charlieablett <cablett@gitlab.com> | 2019-05-02 03:16:49 +0300 |
---|---|---|
committer | charlieablett <cablett@gitlab.com> | 2019-05-30 09:27:28 +0300 |
commit | 2c011cb5b452409db7fe1c810f1ad7440a6cedce (patch) | |
tree | f2b85b2ae667dd2673090efa0d984da328d0e031 /spec | |
parent | 1f37aed1c917260eefda63a18d3a9af91c4a1abb (diff) |
Implement logger analyzer
- Modify GraphqlLogger to subclass JsonLogger
- Replace the single-line analyser with one that can log all the GraphQL
query related information in one place.
- Implement analyzer behavior with spec
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb | 27 | ||||
-rw-r--r-- | spec/lib/gitlab/graphql_logger_spec.rb | 12 | ||||
-rw-r--r-- | spec/requests/api/graphql_spec.rb | 11 |
3 files changed, 41 insertions, 9 deletions
diff --git a/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb new file mode 100644 index 00000000000..53a1d7f8e42 --- /dev/null +++ b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do + + subject { described_class.new } + let(:query_string) { "abc" } + let(:provided_variables) { { a: 1, b: 2, c: 3 } } + let(:complexity) { 4 } + let(:depth) { 2 } + let(:expected_hash) do + { query_string: query_string, + variables: provided_variables, + complexity: complexity, + depth: depth } + end + + it 'assembles a hash' do + query = OpenStruct.new(query_string: query_string, provided_variables: provided_variables) + + subject.initial_value(query) + + expect(subject.instance_variable_get("@info_hash")).to eq expected_hash + end + +end diff --git a/spec/lib/gitlab/graphql_logger_spec.rb b/spec/lib/gitlab/graphql_logger_spec.rb index 51c77181927..aeeed0b2ca1 100644 --- a/spec/lib/gitlab/graphql_logger_spec.rb +++ b/spec/lib/gitlab/graphql_logger_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe Gitlab::GraphqlLogger, :request_store do +describe Gitlab::GraphqlLogger do subject { described_class.new('/dev/null') } let(:now) { Time.now } @@ -10,12 +12,4 @@ describe Gitlab::GraphqlLogger, :request_store do subject.info('hello world') subject.error('hello again') end - - describe '#format_message' do - it 'formats properly' do - output = subject.format_message('INFO', now, 'test', 'Hello world') - - expect(output).to match(/Hello world/) - end - end end diff --git a/spec/requests/api/graphql_spec.rb b/spec/requests/api/graphql_spec.rb index cca87c16f27..103b02ba7a7 100644 --- a/spec/requests/api/graphql_spec.rb +++ b/spec/requests/api/graphql_spec.rb @@ -16,6 +16,17 @@ describe 'GraphQL' do end end + context 'logging' do + it 'logs the query' do + expected = { query_string: query, variables: {}, duration: anything } + + expect(Gitlab::GraphqlLogger).to receive(:info).with(expected) + + post_graphql(query) + end + + end + context 'invalid variables' do it 'returns an error' do post_graphql(query, variables: "This is not JSON") |