summaryrefslogtreecommitdiff
path: root/spec
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
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')
-rw-r--r--spec/graphql/types/base_field_spec.rb27
-rw-r--r--spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb29
-rw-r--r--spec/requests/api/graphql_spec.rb2
3 files changed, 34 insertions, 24 deletions
diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb
index 0be83ea60c4..10913e530cf 100644
--- a/spec/graphql/types/base_field_spec.rb
+++ b/spec/graphql/types/base_field_spec.rb
@@ -74,9 +74,11 @@ describe Types::BaseField do
context 'calls_gitaly' do
context 'for fields with a resolver' do
it 'adds 1 if true' do
- field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true)
+ with_gitaly_field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, resolver_class: resolver, null: true, calls_gitaly: true)
+ without_gitaly_field = described_class.new(name: 'test', type: GraphQL::STRING_TYPE, resolver_class: resolver, null: true)
+ base_result = without_gitaly_field.to_graphql.complexity.call({}, {}, 2)
- expect(field.to_graphql.complexity).to eq 2
+ expect(with_gitaly_field.to_graphql.complexity.call({}, {}, 2)).to eq base_result + 1
end
end
@@ -100,26 +102,5 @@ describe Types::BaseField do
expect(field.to_graphql.complexity).to eq 12
end
end
-
- describe '#calls_gitaly_check' do
- let(:gitaly_field) { described_class.new(name: 'test', type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true) }
- let(:no_gitaly_field) { described_class.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 { no_gitaly_field.send(:calls_gitaly_check, 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 { gitaly_field.send(:calls_gitaly_check, 1) }.not_to raise_error
- end
-
- it 'raises an error if calls_gitaly: is false or not defined' do
- expect { no_gitaly_field.send(:calls_gitaly_check, 1) }.to raise_error(/please add `calls_gitaly: true`/)
- end
- end
- end
end
end
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
diff --git a/spec/requests/api/graphql_spec.rb b/spec/requests/api/graphql_spec.rb
index d78b17827a6..67371cb35b6 100644
--- a/spec/requests/api/graphql_spec.rb
+++ b/spec/requests/api/graphql_spec.rb
@@ -137,7 +137,7 @@ describe 'GraphQL' do
let(:user) { create(:user) }
let(:query) do
- graphql_query_for('project', { 'fullPath' => project.full_path }, %w(forksCount))
+ graphql_query_for('project', { 'fullPath' => project.full_path }, %w(id))
end
before do