summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-15 18:08:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-15 18:08:34 +0000
commit571d993b49313dd806bd3f6af16d36c26d9d28ca (patch)
tree06bd12c4b56b97881aef8a00d4d46698de1eb63f /spec
parent9044365a91112d426fbbfba07eca595652bbe2df (diff)
downloadgitlab-ce-571d993b49313dd806bd3f6af16d36c26d9d28ca.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/environments/sample_metrics_controller_spec.rb11
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/service.json1
-rw-r--r--spec/frontend/error_tracking/components/error_details_spec.js5
-rw-r--r--spec/frontend/error_tracking/store/actions_spec.js78
-rw-r--r--spec/frontend/error_tracking/store/details/actions_spec.js2
-rw-r--r--spec/helpers/projects/error_tracking_helper_spec.rb5
-rw-r--r--spec/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications_spec.rb75
-rw-r--r--spec/lib/gitlab/group_search_results_spec.rb6
-rw-r--r--spec/lib/gitlab/metrics/dashboard/processor_spec.rb18
-rw-r--r--spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb22
-rw-r--r--spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb134
-rw-r--r--spec/models/diff_viewer/base_spec.rb28
-rw-r--r--spec/requests/api/services_spec.rb2
-rw-r--r--spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb102
-rw-r--r--spec/support/cycle_analytics_helpers/test_generation.rb2
-rw-r--r--spec/support/migrations_helpers/prometheus_service_helpers.rb35
16 files changed, 485 insertions, 41 deletions
diff --git a/spec/controllers/projects/environments/sample_metrics_controller_spec.rb b/spec/controllers/projects/environments/sample_metrics_controller_spec.rb
index a1fec46d3a0..19b07a2ccc4 100644
--- a/spec/controllers/projects/environments/sample_metrics_controller_spec.rb
+++ b/spec/controllers/projects/environments/sample_metrics_controller_spec.rb
@@ -9,17 +9,6 @@ describe Projects::Environments::SampleMetricsController do
let_it_be(:environment) { create(:environment, project: project) }
let_it_be(:user) { create(:user) }
- before(:context) do
- RSpec::Mocks.with_temporary_scope do
- stub_env('USE_SAMPLE_METRICS', 'true')
- Rails.application.reload_routes!
- end
- end
-
- after(:context) do
- Rails.application.reload_routes!
- end
-
before do
project.add_reporter(user)
sign_in(user)
diff --git a/spec/fixtures/api/schemas/public_api/v4/service.json b/spec/fixtures/api/schemas/public_api/v4/service.json
index a024e38acad..b6f13d1cfe7 100644
--- a/spec/fixtures/api/schemas/public_api/v4/service.json
+++ b/spec/fixtures/api/schemas/public_api/v4/service.json
@@ -3,6 +3,7 @@
"properties": {
"id": { "type": "integer" },
"title": { "type": "string" },
+ "slug": { "type": "string" },
"created_at": { "type": "date-time" },
"updated_at": { "type": "date-time" },
"active": { "type": "boolean" },
diff --git a/spec/frontend/error_tracking/components/error_details_spec.js b/spec/frontend/error_tracking/components/error_details_spec.js
index b5ce9383eb9..d62bda78e9a 100644
--- a/spec/frontend/error_tracking/components/error_details_spec.js
+++ b/spec/frontend/error_tracking/components/error_details_spec.js
@@ -29,6 +29,8 @@ describe('ErrorDetails', () => {
propsData: {
issueId: '123',
projectPath: '/root/gitlab-test',
+ listPath: '/error_tracking',
+ issueUpdatePath: '/123',
issueDetailsPath: '/123/details',
issueStackTracePath: '/stacktrace',
projectIssuesPath: '/test-project/issues/',
@@ -122,6 +124,7 @@ describe('ErrorDetails', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
expect(wrapper.find(Stacktrace).exists()).toBe(false);
expect(wrapper.find(GlBadge).exists()).toBe(false);
+ expect(wrapper.findAll('button').length).toBe(3);
});
describe('Badges', () => {
@@ -185,7 +188,7 @@ describe('ErrorDetails', () => {
it('should submit the form', () => {
window.HTMLFormElement.prototype.submit = () => {};
const submitSpy = jest.spyOn(wrapper.vm.$refs.sentryIssueForm, 'submit');
- wrapper.find('button').trigger('click');
+ wrapper.find('[data-qa-selector="create_issue_button"]').trigger('click');
expect(submitSpy).toHaveBeenCalled();
submitSpy.mockRestore();
});
diff --git a/spec/frontend/error_tracking/store/actions_spec.js b/spec/frontend/error_tracking/store/actions_spec.js
new file mode 100644
index 00000000000..8bc53d94345
--- /dev/null
+++ b/spec/frontend/error_tracking/store/actions_spec.js
@@ -0,0 +1,78 @@
+import MockAdapter from 'axios-mock-adapter';
+import testAction from 'helpers/vuex_action_helper';
+import axios from '~/lib/utils/axios_utils';
+import createFlash from '~/flash';
+import * as actions from '~/error_tracking/store/actions';
+import * as types from '~/error_tracking/store/mutation_types';
+import { visitUrl } from '~/lib/utils/url_utility';
+
+jest.mock('~/flash.js');
+jest.mock('~/lib/utils/url_utility');
+
+let mock;
+
+describe('Sentry common store actions', () => {
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
+
+ afterEach(() => {
+ mock.restore();
+ createFlash.mockClear();
+ });
+
+ describe('updateStatus', () => {
+ const endpoint = '123/stacktrace';
+ const redirectUrl = '/list';
+ const status = 'resolved';
+
+ it('should handle successful status update', done => {
+ mock.onPut().reply(200, {});
+ testAction(
+ actions.updateStatus,
+ { endpoint, redirectUrl, status },
+ {},
+ [
+ {
+ payload: true,
+ type: types.SET_UPDATING_RESOLVE_STATUS,
+ },
+ {
+ payload: false,
+ type: 'SET_UPDATING_RESOLVE_STATUS',
+ },
+ ],
+ [],
+ () => {
+ done();
+ expect(visitUrl).toHaveBeenCalledWith(redirectUrl);
+ },
+ );
+ });
+
+ it('should handle unsuccessful status update', done => {
+ mock.onPut().reply(400, {});
+ testAction(
+ actions.updateStatus,
+ { endpoint, redirectUrl, status },
+ {},
+ [
+ {
+ payload: true,
+ type: types.SET_UPDATING_RESOLVE_STATUS,
+ },
+ {
+ payload: false,
+ type: types.SET_UPDATING_RESOLVE_STATUS,
+ },
+ ],
+ [],
+ () => {
+ expect(visitUrl).not.toHaveBeenCalled();
+ expect(createFlash).toHaveBeenCalledTimes(1);
+ done();
+ },
+ );
+ });
+ });
+});
diff --git a/spec/frontend/error_tracking/store/details/actions_spec.js b/spec/frontend/error_tracking/store/details/actions_spec.js
index 0866f76aeef..129760bb705 100644
--- a/spec/frontend/error_tracking/store/details/actions_spec.js
+++ b/spec/frontend/error_tracking/store/details/actions_spec.js
@@ -6,6 +6,8 @@ import * as actions from '~/error_tracking/store/details/actions';
import * as types from '~/error_tracking/store/details/mutation_types';
jest.mock('~/flash.js');
+jest.mock('~/lib/utils/url_utility');
+
let mock;
describe('Sentry error details store actions', () => {
diff --git a/spec/helpers/projects/error_tracking_helper_spec.rb b/spec/helpers/projects/error_tracking_helper_spec.rb
index 7c67448034b..583b1c76d7b 100644
--- a/spec/helpers/projects/error_tracking_helper_spec.rb
+++ b/spec/helpers/projects/error_tracking_helper_spec.rb
@@ -79,6 +79,7 @@ describe Projects::ErrorTrackingHelper do
describe '#error_details_data' do
let(:issue_id) { 1234 }
let(:route_params) { [project.owner, project, issue_id, { format: :json }] }
+ let(:list_path) { project_error_tracking_index_path(project) }
let(:details_path) { details_namespace_project_error_tracking_index_path(*route_params) }
let(:project_path) { project.full_path }
let(:stack_trace_path) { stack_trace_namespace_project_error_tracking_index_path(*route_params) }
@@ -86,6 +87,10 @@ describe Projects::ErrorTrackingHelper do
let(:result) { helper.error_details_data(project, issue_id) }
+ it 'returns the correct list path' do
+ expect(result['list-path']).to eq list_path
+ end
+
it 'returns the correct issue id' do
expect(result['issue-id']).to eq issue_id
end
diff --git a/spec/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications_spec.rb b/spec/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications_spec.rb
new file mode 100644
index 00000000000..0edf87e1354
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications_spec.rb
@@ -0,0 +1,75 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::BackgroundMigration::ActivatePrometheusServicesForSharedClusterApplications, :migration, schema: 2020_01_14_113341 do
+ include MigrationHelpers::PrometheusServiceHelpers
+
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:services) { table(:services) }
+ let(:namespace) { namespaces.create(name: 'user', path: 'user') }
+ let(:project) { projects.create(namespace_id: namespace.id) }
+
+ let(:columns) do
+ %w(project_id active properties type template push_events
+ issues_events merge_requests_events tag_push_events
+ note_events category default wiki_page_events pipeline_events
+ confidential_issues_events commit_events job_events
+ confidential_note_events deployment_events)
+ end
+
+ describe '#perform' do
+ it 'is idempotent' do
+ expect { subject.perform(project.id) }.to change { services.order(:id).map { |row| row.attributes } }
+
+ expect { subject.perform(project.id) }.not_to change { services.order(:id).map { |row| row.attributes } }
+ end
+
+ context 'non prometheus services' do
+ it 'does not change them' do
+ other_type = 'SomeOtherService'
+ services.create(service_params_for(project.id, active: true, type: other_type))
+
+ expect { subject.perform(project.id) }.not_to change { services.where(type: other_type).order(:id).map { |row| row.attributes } }
+ end
+ end
+
+ context 'prometheus services are configured manually ' do
+ it 'does not change them' do
+ properties = '{"api_url":"http://test.dev","manual_configuration":"1"}'
+ services.create(service_params_for(project.id, properties: properties, active: false))
+
+ expect { subject.perform(project.id) }.not_to change { services.order(:id).map { |row| row.attributes } }
+ end
+ end
+
+ context 'prometheus integration services do not exist' do
+ it 'creates missing services entries' do
+ subject.perform(project.id)
+
+ rows = services.order(:id).map { |row| row.attributes.slice(*columns).symbolize_keys }
+
+ expect([service_params_for(project.id, active: true)]).to eq rows
+ end
+ end
+
+ context 'prometheus integration services exist' do
+ context 'in active state' do
+ it 'does not change them' do
+ services.create(service_params_for(project.id, active: true))
+
+ expect { subject.perform(project.id) }.not_to change { services.order(:id).map { |row| row.attributes } }
+ end
+ end
+
+ context 'not in active state' do
+ it 'sets active attribute to true' do
+ service = services.create(service_params_for(project.id))
+
+ expect { subject.perform(project.id) }.to change { service.reload.active? }.from(false).to(true)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/group_search_results_spec.rb b/spec/lib/gitlab/group_search_results_spec.rb
index 570b0cb7401..746f505c877 100644
--- a/spec/lib/gitlab/group_search_results_spec.rb
+++ b/spec/lib/gitlab/group_search_results_spec.rb
@@ -67,5 +67,11 @@ describe Gitlab::GroupSearchResults do
expect(result).to eq []
end
+
+ it 'sets include_subgroups flag by default' do
+ result = described_class.new(user, anything, group, 'gob')
+
+ expect(result.issuable_params[:include_subgroups]).to eq(true)
+ end
end
end
diff --git a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
index 4fa136bc405..e186a383059 100644
--- a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
+++ b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
@@ -86,6 +86,16 @@ describe Gitlab::Metrics::Dashboard::Processor do
expect(metrics).to eq %w(metric_b metric_a2 metric_a1)
end
end
+
+ context 'when sample_metrics are requested' do
+ let(:process_params) { [project, dashboard_yml, sequence, { environment: environment, sample_metrics: true }] }
+
+ it 'includes a sample metrics path for the prometheus endpoint with each metric' do
+ expect(all_metrics).to satisfy_all do |metric|
+ metric[:prometheus_endpoint_path] == sample_metrics_path(metric[:id])
+ end
+ end
+ end
end
shared_examples_for 'errors with message' do |expected_message|
@@ -147,4 +157,12 @@ describe Gitlab::Metrics::Dashboard::Processor do
query: query
)
end
+
+ def sample_metrics_path(metric)
+ Gitlab::Routing.url_helpers.sample_metrics_project_environment_path(
+ project,
+ environment,
+ identifier: metric
+ )
+ end
end
diff --git a/spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb b/spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb
new file mode 100644
index 00000000000..2d12fec5cb3
--- /dev/null
+++ b/spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20200114112932_add_temporary_partial_index_on_project_id_to_services.rb')
+
+describe AddTemporaryPartialIndexOnProjectIdToServices, :migration do
+ let(:migration) { described_class.new }
+
+ describe '#up' do
+ it 'creates temporary partial index on type' do
+ expect { migration.up }.to change { migration.index_exists?(:services, :project_id, name: described_class::INDEX_NAME) }.from(false).to(true)
+ end
+ end
+
+ describe '#down' do
+ it 'removes temporary partial index on type' do
+ migration.up
+
+ expect { migration.down }.to change { migration.index_exists?(:services, :project_id, name: described_class::INDEX_NAME) }.from(true).to(false)
+ end
+ end
+end
diff --git a/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb b/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb
new file mode 100644
index 00000000000..83f994c2a94
--- /dev/null
+++ b/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb
@@ -0,0 +1,134 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb')
+
+describe PatchPrometheusServicesForSharedClusterApplications, :migration, :sidekiq do
+ include MigrationHelpers::PrometheusServiceHelpers
+
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:services) { table(:services) }
+ let(:clusters) { table(:clusters) }
+ let(:cluster_groups) { table(:cluster_groups) }
+ let(:clusters_applications_prometheus) { table(:clusters_applications_prometheus) }
+ let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
+
+ let(:application_statuses) do
+ {
+ errored: -1,
+ installed: 3,
+ updated: 5
+ }
+ end
+
+ let(:cluster_types) do
+ {
+ instance_type: 1,
+ group_type: 2
+ }
+ end
+
+ describe '#up' do
+ let!(:project_with_missing_service) { projects.create!(name: 'gitlab', path: 'gitlab-ce', namespace_id: namespace.id) }
+ let(:project_with_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
+ let(:project_with_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
+ let(:project_with_manual_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
+ let(:project_with_manual_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
+ let(:project_with_active_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
+ let(:project_with_inactive_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
+
+ before do
+ services.create(service_params_for(project_with_inactive_service.id, active: false))
+ services.create(service_params_for(project_with_active_service.id, active: true))
+ services.create(service_params_for(project_with_active_not_prometheus_service.id, active: true, type: 'other'))
+ services.create(service_params_for(project_with_inactive_not_prometheus_service.id, active: false, type: 'other'))
+ services.create(service_params_for(project_with_manual_inactive_service.id, active: false, properties: { some: 'data' }.to_json))
+ services.create(service_params_for(project_with_manual_active_service.id, active: true, properties: { some: 'data' }.to_json))
+ end
+
+ shared_examples 'patch prometheus services post migration' do
+ context 'prometheus application is installed on the cluster' do
+ it 'schedules a background migration' do
+ clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:installed], version: '123')
+
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id],
+ ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id],
+ ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id],
+ ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]]
+
+ migrate!
+
+ enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] }
+ expect(enqueued_migrations).to match_array(background_migrations)
+ end
+ end
+ end
+ end
+
+ context 'prometheus application was recently updated on the cluster' do
+ it 'schedules a background migration' do
+ clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:updated], version: '123')
+
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id],
+ ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id],
+ ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id],
+ ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]]
+
+ migrate!
+
+ enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] }
+ expect(enqueued_migrations).to match_array(background_migrations)
+ end
+ end
+ end
+ end
+
+ context 'prometheus application failed to install on the cluster' do
+ it 'does not schedule a background migration' do
+ clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:errored], version: '123')
+
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migrate!
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq 0
+ end
+ end
+ end
+ end
+
+ context 'prometheus application is NOT installed on the cluster' do
+ it 'does not schedule a background migration' do
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migrate!
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq 0
+ end
+ end
+ end
+ end
+ end
+
+ context 'Cluster is group_type' do
+ let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:group_type]) }
+
+ before do
+ cluster_groups.create(group_id: namespace.id, cluster_id: cluster.id)
+ end
+
+ it_behaves_like 'patch prometheus services post migration'
+ end
+
+ context 'Cluster is instance_type' do
+ let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:instance_type]) }
+
+ it_behaves_like 'patch prometheus services post migration'
+ end
+ end
+end
diff --git a/spec/models/diff_viewer/base_spec.rb b/spec/models/diff_viewer/base_spec.rb
index 019597993cc..0a1c4c5560e 100644
--- a/spec/models/diff_viewer/base_spec.rb
+++ b/spec/models/diff_viewer/base_spec.rb
@@ -43,34 +43,6 @@ describe DiffViewer::Base do
end
end
- context 'when the file type is supported' do
- let(:commit) { project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') }
- let(:diff_file) { commit.diffs.diff_file_with_new_path('LICENSE') }
-
- before do
- viewer_class.file_types = %i(license)
- viewer_class.binary = false
- end
-
- context 'when the binaryness matches' do
- it 'returns true' do
- expect(viewer_class.can_render?(diff_file)).to be_truthy
- end
- end
-
- context 'when the binaryness does not match' do
- before do
- allow_next_instance_of(Blob) do |instance|
- allow(instance).to receive(:binary_in_repo?).and_return(true)
- end
- end
-
- it 'returns false' do
- expect(viewer_class.can_render?(diff_file)).to be_falsey
- end
- end
- end
-
context 'when the extension and file type are not supported' do
it 'returns false' do
expect(viewer_class.can_render?(diff_file)).to be_falsey
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb
index 26407e8a45e..08f58387bf8 100644
--- a/spec/requests/api/services_spec.rb
+++ b/spec/requests/api/services_spec.rb
@@ -35,6 +35,7 @@ describe API::Services do
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array
expect(json_response.count).to eq(1)
+ expect(json_response.first['slug']).to eq('emails-on-push')
expect(response).to match_response_schema('public_api/v4/services')
end
end
@@ -61,6 +62,7 @@ describe API::Services do
put api("/projects/#{project.id}/services/#{dashed_service}?#{query_strings}", user), params: service_attrs
expect(response).to have_gitlab_http_status(200)
+ expect(json_response['slug']).to eq(dashed_service)
events.each do |event|
next if event == "foo"
diff --git a/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb b/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb
new file mode 100644
index 00000000000..12bdacdee3c
--- /dev/null
+++ b/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb
@@ -0,0 +1,102 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+require 'rspec-parameterized'
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../../rubocop/cop/rspec/have_gitlab_http_status'
+
+describe RuboCop::Cop::RSpec::HaveGitlabHttpStatus do
+ include CopHelper
+
+ using RSpec::Parameterized::TableSyntax
+
+ let(:source_file) { 'spec/foo_spec.rb' }
+
+ subject(:cop) { described_class.new }
+
+ shared_examples 'offense' do |code|
+ it 'registers an offense' do
+ inspect_source(code, source_file)
+
+ expect(cop.offenses.size).to eq(1)
+ expect(cop.offenses.map(&:line)).to eq([1])
+ expect(cop.highlights).to eq([code])
+ end
+ end
+
+ shared_examples 'no offense' do |code|
+ it 'does not register an offense' do
+ inspect_source(code)
+
+ expect(cop.offenses).to be_empty
+ end
+ end
+
+ shared_examples 'autocorrect' do |bad, good|
+ it 'autocorrects' do
+ autocorrected = autocorrect_source(bad, source_file)
+
+ expect(autocorrected).to eql(good)
+ end
+ end
+
+ shared_examples 'no autocorrect' do |code|
+ it 'does not autocorrect' do
+ autocorrected = autocorrect_source(code, source_file)
+
+ expect(autocorrected).to eql(code)
+ end
+ end
+
+ describe 'offenses and autocorrections' do
+ where(:bad, :good) do
+ 'have_http_status(:ok)' | 'have_gitlab_http_status(:ok)'
+ 'have_http_status(204)' | 'have_gitlab_http_status(:no_content)'
+ 'have_gitlab_http_status(201)' | 'have_gitlab_http_status(:created)'
+ 'have_http_status(var)' | 'have_gitlab_http_status(var)'
+ 'have_http_status(:success)' | 'have_gitlab_http_status(:success)'
+ 'have_http_status(:invalid)' | 'have_gitlab_http_status(:invalid)'
+ end
+
+ with_them do
+ include_examples 'offense', params[:bad]
+ include_examples 'no offense', params[:good]
+ include_examples 'autocorrect', params[:bad], params[:good]
+ include_examples 'no autocorrect', params[:good]
+ end
+ end
+
+ describe 'partially autocorrects invalid numeric status' do
+ where(:bad, :good) do
+ 'have_http_status(-1)' | 'have_gitlab_http_status(-1)'
+ end
+
+ with_them do
+ include_examples 'offense', params[:bad]
+ include_examples 'offense', params[:good]
+ include_examples 'autocorrect', params[:bad], params[:good]
+ include_examples 'no autocorrect', params[:good]
+ end
+ end
+
+ describe 'ignore' do
+ where(:code) do
+ [
+ 'have_http_status',
+ 'have_http_status { }',
+ 'have_http_status(200, arg)',
+ 'have_gitlab_http_status',
+ 'have_gitlab_http_status { }',
+ 'have_gitlab_http_status(200, arg)'
+ ]
+ end
+
+ with_them do
+ include_examples 'no offense', params[:code]
+ include_examples 'no autocorrect', params[:code]
+ end
+ end
+end
diff --git a/spec/support/cycle_analytics_helpers/test_generation.rb b/spec/support/cycle_analytics_helpers/test_generation.rb
index 2fac6bfb30b..34018263339 100644
--- a/spec/support/cycle_analytics_helpers/test_generation.rb
+++ b/spec/support/cycle_analytics_helpers/test_generation.rb
@@ -117,7 +117,7 @@ module CycleAnalyticsHelpers
data = data_fn[self]
end_time = rand(1..10).days.from_now
- end_time_conditions.each_with_index do |(condition_name, condition_fn), index|
+ end_time_conditions.each_with_index do |(_condition_name, condition_fn), index|
Timecop.freeze(end_time + index.days) { condition_fn[self, data] }
end
diff --git a/spec/support/migrations_helpers/prometheus_service_helpers.rb b/spec/support/migrations_helpers/prometheus_service_helpers.rb
new file mode 100644
index 00000000000..88f2f71ee1e
--- /dev/null
+++ b/spec/support/migrations_helpers/prometheus_service_helpers.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module MigrationHelpers
+ module PrometheusServiceHelpers
+ def service_params_for(project_id, params = {})
+ {
+ project_id: project_id,
+ active: false,
+ properties: '{}',
+ type: 'PrometheusService',
+ template: false,
+ push_events: true,
+ issues_events: true,
+ merge_requests_events: true,
+ tag_push_events: true,
+ note_events: true,
+ category: 'monitoring',
+ default: false,
+ wiki_page_events: true,
+ pipeline_events: true,
+ confidential_issues_events: true,
+ commit_events: true,
+ job_events: true,
+ confidential_note_events: true,
+ deployment_events: false
+ }.merge(params)
+ end
+
+ def row_attributes(entity)
+ entity.attributes.with_indifferent_access.tap do |hash|
+ hash.merge!(hash.slice(:created_at, :updated_at).transform_values { |v| v.to_s(:db) })
+ end
+ end
+ end
+end