summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/graphql
diff options
context:
space:
mode:
authorcharlieablett <cablett@gitlab.com>2019-06-28 13:24:47 +1200
committercharlieablett <cablett@gitlab.com>2019-07-03 22:53:13 +1200
commitcf1b0d10bcdde69f05695a2e9a0d380c6badb6d1 (patch)
tree9bcc0d99dc22a2f4fa2601f1b904c7a418766616 /spec/lib/gitlab/graphql
parenta11fe5de4408595cc8b2b091cbbb76e423c98f34 (diff)
downloadgitlab-ce-cf1b0d10bcdde69f05695a2e9a0d380c6badb6d1.tar.gz
Address reviewer comments
- Add 1 for all fields that call Gitaly (with resolvers or without) - Clarify comment regarding Gitaly call alert - Expose predicate `calls_gitaly?` instead of ivar
Diffstat (limited to 'spec/lib/gitlab/graphql')
-rw-r--r--spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb b/spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb
new file mode 100644
index 00000000000..92d200bfd4e
--- /dev/null
+++ b/spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+describe Gitlab::Graphql::CallsGitaly::Instrumentation do
+ subject { described_class.new }
+
+ context 'when considering complexity' do
+ describe '#calls_gitaly_check' do
+ let(:gitaly_field) { Types::BaseField.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true) }
+ let(:no_gitaly_field) { Types::BaseField.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, calls_gitaly: false) }
+
+ context 'if there are no Gitaly calls' do
+ it 'does not raise an error if calls_gitaly is false' do
+ expect { subject.send(:calls_gitaly_check, no_gitaly_field, 0) }.not_to raise_error
+ end
+ end
+
+ context 'if there is at least 1 Gitaly call' do
+ it 'does not raise an error if calls_gitaly is true' do
+ expect { subject.send(:calls_gitaly_check, gitaly_field, 1) }.not_to raise_error
+ end
+
+ it 'raises an error if calls_gitaly: is false or not defined' do
+ expect { subject.send(:calls_gitaly_check, no_gitaly_field, 1) }.to raise_error(/please add `calls_gitaly: true`/)
+ end
+ end
+ end
+ end
+end