Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 21:25:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 21:25:58 +0300
commita5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch)
treefb69158581673816a8cd895f9d352dcb3c678b1e /spec/rubocop/cop
parentd16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff)
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/rubocop/cop')
-rw-r--r--spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb108
-rw-r--r--spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb64
2 files changed, 172 insertions, 0 deletions
diff --git a/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb b/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb
new file mode 100644
index 00000000000..56aecc3ec4e
--- /dev/null
+++ b/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb
@@ -0,0 +1,108 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+require_relative '../../../../rubocop/cop/usage_data/histogram_with_large_table'
+
+RSpec.describe RuboCop::Cop::UsageData::HistogramWithLargeTable do
+ let(:high_traffic_models) { %w[Issue Ci::Build] }
+ let(:msg) { 'Avoid histogram method on' }
+
+ let(:config) do
+ RuboCop::Config.new('UsageData/HistogramWithLargeTable' => {
+ 'HighTrafficModels' => high_traffic_models
+ })
+ end
+
+ subject(:cop) { described_class.new(config) }
+
+ context 'with large tables' do
+ context 'with one-level constants' do
+ context 'when calling histogram(Issue)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(Issue, :project_id, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue
+ CODE
+ end
+ end
+
+ context 'when calling histogram(::Issue)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(::Issue, :project_id, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue
+ CODE
+ end
+ end
+
+ context 'when calling histogram(Issue.closed)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(Issue.closed, :project_id, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue
+ CODE
+ end
+ end
+
+ context 'when calling histogram(::Issue.closed)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(::Issue.closed, :project_id, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue
+ CODE
+ end
+ end
+ end
+
+ context 'with two-level constants' do
+ context 'when calling histogram(::Ci::Build)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(::Ci::Build, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build
+ CODE
+ end
+ end
+
+ context 'when calling histogram(::Ci::Build.active)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(::Ci::Build.active, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build
+ CODE
+ end
+ end
+
+ context 'when calling histogram(Ci::Build)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(Ci::Build, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build
+ CODE
+ end
+ end
+
+ context 'when calling histogram(Ci::Build.active)' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ histogram(Ci::Build.active, buckets: 1..100)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build
+ CODE
+ end
+ end
+ end
+ end
+
+ context 'with non related class' do
+ it 'does not register an offense' do
+ expect_no_offenses('histogram(MergeRequest, buckets: 1..100)')
+ end
+ end
+
+ context 'with non related method' do
+ it 'does not register an offense' do
+ expect_no_offenses('count(Issue, buckets: 1..100)')
+ end
+ end
+end
diff --git a/spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb b/spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb
new file mode 100644
index 00000000000..31324331e61
--- /dev/null
+++ b/spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+require_relative '../../../../rubocop/cop/usage_data/instrumentation_superclass'
+
+RSpec.describe RuboCop::Cop::UsageData::InstrumentationSuperclass do
+ let(:allowed_classes) { %i[GenericMetric DatabaseMetric RedisHllMetric] }
+ let(:msg) { "Instrumentation classes should subclass one of the following: #{allowed_classes.join(', ')}." }
+
+ let(:config) do
+ RuboCop::Config.new('UsageData/InstrumentationSuperclass' => {
+ 'AllowedClasses' => allowed_classes
+ })
+ end
+
+ subject(:cop) { described_class.new(config) }
+
+ context 'with class definition' do
+ context 'when inheriting from allowed superclass' do
+ it 'does not register an offense' do
+ expect_no_offenses('class NewMetric < GenericMetric; end')
+ end
+ end
+
+ context 'when inheriting from some other superclass' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ class NewMetric < BaseMetric; end
+ ^^^^^^^^^^ #{msg}
+ CODE
+ end
+ end
+
+ context 'when not inheriting' do
+ it 'does not register an offense' do
+ expect_no_offenses('class NewMetric; end')
+ end
+ end
+ end
+
+ context 'with dynamic class definition' do
+ context 'when inheriting from allowed superclass' do
+ it 'does not register an offense' do
+ expect_no_offenses('NewMetric = Class.new(GenericMetric)')
+ end
+ end
+
+ context 'when inheriting from some other superclass' do
+ it 'registers an offense' do
+ expect_offense(<<~CODE)
+ NewMetric = Class.new(BaseMetric)
+ ^^^^^^^^^^ #{msg}
+ CODE
+ end
+ end
+
+ context 'when not inheriting' do
+ it 'does not register an offense' do
+ expect_no_offenses('NewMetric = Class.new')
+ end
+ end
+ end
+end