summaryrefslogtreecommitdiff
path: root/spec/services/projects
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/services/projects
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/services/projects')
-rw-r--r--spec/services/projects/after_import_service_spec.rb22
-rw-r--r--spec/services/projects/after_rename_service_spec.rb2
-rw-r--r--spec/services/projects/alerting/notify_service_spec.rb110
-rw-r--r--spec/services/projects/auto_devops/disable_service_spec.rb2
-rw-r--r--spec/services/projects/autocomplete_service_spec.rb2
-rw-r--r--spec/services/projects/batch_open_issues_count_service_spec.rb2
-rw-r--r--spec/services/projects/cleanup_service_spec.rb2
-rw-r--r--spec/services/projects/container_repository/cleanup_tags_service_spec.rb2
-rw-r--r--spec/services/projects/container_repository/delete_tags_service_spec.rb118
-rw-r--r--spec/services/projects/container_repository/destroy_service_spec.rb2
-rw-r--r--spec/services/projects/count_service_spec.rb2
-rw-r--r--spec/services/projects/create_from_template_service_spec.rb2
-rw-r--r--spec/services/projects/create_service_spec.rb61
-rw-r--r--spec/services/projects/deploy_tokens/create_service_spec.rb2
-rw-r--r--spec/services/projects/deploy_tokens/destroy_service_spec.rb2
-rw-r--r--spec/services/projects/destroy_rollback_service_spec.rb2
-rw-r--r--spec/services/projects/destroy_service_spec.rb2
-rw-r--r--spec/services/projects/detect_repository_languages_service_spec.rb2
-rw-r--r--spec/services/projects/download_service_spec.rb2
-rw-r--r--spec/services/projects/enable_deploy_key_service_spec.rb2
-rw-r--r--spec/services/projects/fetch_statistics_increment_service_spec.rb2
-rw-r--r--spec/services/projects/fork_service_spec.rb6
-rw-r--r--spec/services/projects/forks_count_service_spec.rb2
-rw-r--r--spec/services/projects/git_deduplication_service_spec.rb4
-rw-r--r--spec/services/projects/gitlab_projects_import_service_spec.rb2
-rw-r--r--spec/services/projects/group_links/create_service_spec.rb50
-rw-r--r--spec/services/projects/group_links/destroy_service_spec.rb2
-rw-r--r--spec/services/projects/group_links/update_service_spec.rb2
-rw-r--r--spec/services/projects/hashed_storage/base_attachment_service_spec.rb2
-rw-r--r--spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb2
-rw-r--r--spec/services/projects/hashed_storage/migrate_repository_service_spec.rb2
-rw-r--r--spec/services/projects/hashed_storage/migration_service_spec.rb2
-rw-r--r--spec/services/projects/hashed_storage/rollback_attachments_service_spec.rb2
-rw-r--r--spec/services/projects/hashed_storage/rollback_repository_service_spec.rb2
-rw-r--r--spec/services/projects/hashed_storage/rollback_service_spec.rb2
-rw-r--r--spec/services/projects/housekeeping_service_spec.rb2
-rw-r--r--spec/services/projects/import_error_filter_spec.rb2
-rw-r--r--spec/services/projects/import_export/export_service_spec.rb2
-rw-r--r--spec/services/projects/import_service_spec.rb2
-rw-r--r--spec/services/projects/lfs_pointers/lfs_download_link_list_service_spec.rb2
-rw-r--r--spec/services/projects/lfs_pointers/lfs_download_service_spec.rb2
-rw-r--r--spec/services/projects/lfs_pointers/lfs_import_service_spec.rb2
-rw-r--r--spec/services/projects/lfs_pointers/lfs_link_service_spec.rb2
-rw-r--r--spec/services/projects/lfs_pointers/lfs_object_download_list_service_spec.rb2
-rw-r--r--spec/services/projects/move_access_service_spec.rb2
-rw-r--r--spec/services/projects/move_deploy_keys_projects_service_spec.rb2
-rw-r--r--spec/services/projects/move_forks_service_spec.rb2
-rw-r--r--spec/services/projects/move_lfs_objects_projects_service_spec.rb2
-rw-r--r--spec/services/projects/move_notification_settings_service_spec.rb2
-rw-r--r--spec/services/projects/move_project_authorizations_service_spec.rb2
-rw-r--r--spec/services/projects/move_project_group_links_service_spec.rb2
-rw-r--r--spec/services/projects/move_project_members_service_spec.rb2
-rw-r--r--spec/services/projects/move_users_star_projects_service_spec.rb2
-rw-r--r--spec/services/projects/open_issues_count_service_spec.rb2
-rw-r--r--spec/services/projects/open_merge_requests_count_service_spec.rb2
-rw-r--r--spec/services/projects/operations/update_service_spec.rb2
-rw-r--r--spec/services/projects/overwrite_project_service_spec.rb2
-rw-r--r--spec/services/projects/participants_service_spec.rb2
-rw-r--r--spec/services/projects/prometheus/alerts/create_events_service_spec.rb312
-rw-r--r--spec/services/projects/prometheus/alerts/create_service_spec.rb2
-rw-r--r--spec/services/projects/prometheus/alerts/destroy_service_spec.rb2
-rw-r--r--spec/services/projects/prometheus/alerts/notify_service_spec.rb127
-rw-r--r--spec/services/projects/prometheus/alerts/update_service_spec.rb2
-rw-r--r--spec/services/projects/prometheus/metrics/destroy_service_spec.rb2
-rw-r--r--spec/services/projects/prometheus/metrics/update_service_spec.rb2
-rw-r--r--spec/services/projects/propagate_service_template_spec.rb2
-rw-r--r--spec/services/projects/protect_default_branch_service_spec.rb2
-rw-r--r--spec/services/projects/repository_languages_service_spec.rb2
-rw-r--r--spec/services/projects/transfer_service_spec.rb2
-rw-r--r--spec/services/projects/unlink_fork_service_spec.rb5
-rw-r--r--spec/services/projects/update_pages_configuration_service_spec.rb2
-rw-r--r--spec/services/projects/update_pages_service_spec.rb2
-rw-r--r--spec/services/projects/update_remote_mirror_service_spec.rb2
-rw-r--r--spec/services/projects/update_repository_storage_service_spec.rb38
-rw-r--r--spec/services/projects/update_service_spec.rb2
-rw-r--r--spec/services/projects/update_statistics_service_spec.rb2
76 files changed, 390 insertions, 593 deletions
diff --git a/spec/services/projects/after_import_service_spec.rb b/spec/services/projects/after_import_service_spec.rb
index 82f654cea10..a109348ea19 100644
--- a/spec/services/projects/after_import_service_spec.rb
+++ b/spec/services/projects/after_import_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::AfterImportService do
+RSpec.describe Projects::AfterImportService do
include GitHelpers
subject { described_class.new(project) }
@@ -72,6 +72,26 @@ describe Projects::AfterImportService do
end
end
+ context 'when housekeeping service lease is taken' do
+ let(:exception) { Projects::HousekeepingService::LeaseTaken.new }
+
+ it 'logs the error message' do
+ allow_next_instance_of(Projects::HousekeepingService) do |instance|
+ expect(instance).to receive(:execute).and_raise(exception)
+ end
+
+ expect(Gitlab::Import::Logger).to receive(:info).with(
+ {
+ message: 'Project housekeeping failed',
+ project_full_path: project.full_path,
+ project_id: project.id,
+ 'error.message' => exception.to_s
+ }).and_call_original
+
+ subject.execute
+ end
+ end
+
context 'when after import action throw retriable exception one time' do
let(:exception) { GRPC::DeadlineExceeded.new }
diff --git a/spec/services/projects/after_rename_service_spec.rb b/spec/services/projects/after_rename_service_spec.rb
index b81dd3d7e3f..52136b37c66 100644
--- a/spec/services/projects/after_rename_service_spec.rb
+++ b/spec/services/projects/after_rename_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::AfterRenameService do
+RSpec.describe Projects::AfterRenameService do
let(:rugged_config) { rugged_repo(project.repository).config }
let(:legacy_storage) { Storage::LegacyProject.new(project) }
let(:hashed_storage) { Storage::Hashed.new(project) }
diff --git a/spec/services/projects/alerting/notify_service_spec.rb b/spec/services/projects/alerting/notify_service_spec.rb
index 2f8c2049f85..123b0bad2a8 100644
--- a/spec/services/projects/alerting/notify_service_spec.rb
+++ b/spec/services/projects/alerting/notify_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Alerting::NotifyService do
+RSpec.describe Projects::Alerting::NotifyService do
let_it_be(:project, reload: true) { create(:project) }
before do
@@ -21,7 +21,7 @@ describe Projects::Alerting::NotifyService do
it 'processes issues' do
expect(IncidentManagement::ProcessAlertWorker)
.to receive(:perform_async)
- .with(project.id, kind_of(Hash), kind_of(Integer))
+ .with(nil, nil, kind_of(Integer))
.once
Sidekiq::Testing.inline! do
@@ -64,12 +64,6 @@ describe Projects::Alerting::NotifyService do
end
end
- shared_examples 'NotifyService does not create alert' do
- it 'does not create alert' do
- expect { subject }.not_to change(AlertManagement::Alert, :count)
- end
- end
-
describe '#execute' do
let(:token) { 'invalid-token' }
let(:starts_at) { Time.current.change(usec: 0) }
@@ -107,60 +101,64 @@ describe Projects::Alerting::NotifyService do
end
context 'with valid payload' do
+ shared_examples 'assigns the alert properties' do
+ it 'ensure that created alert has all data properly assigned' do
+ subject
+
+ expect(last_alert_attributes).to match(
+ project_id: project.id,
+ title: payload_raw.fetch(:title),
+ started_at: Time.zone.parse(payload_raw.fetch(:start_time)),
+ severity: payload_raw.fetch(:severity),
+ status: AlertManagement::Alert::STATUSES[:triggered],
+ events: 1,
+ hosts: payload_raw.fetch(:hosts),
+ payload: payload_raw.with_indifferent_access,
+ issue_id: nil,
+ description: payload_raw.fetch(:description),
+ monitoring_tool: payload_raw.fetch(:monitoring_tool),
+ service: payload_raw.fetch(:service),
+ fingerprint: Digest::SHA1.hexdigest(fingerprint),
+ ended_at: nil,
+ prometheus_alert_id: nil,
+ environment_id: nil
+ )
+ end
+ end
+
let(:last_alert_attributes) do
AlertManagement::Alert.last.attributes
.except('id', 'iid', 'created_at', 'updated_at')
.with_indifferent_access
end
- it 'creates AlertManagement::Alert' do
- expect { subject }.to change(AlertManagement::Alert, :count).by(1)
- end
-
- it 'created alert has all data properly assigned' do
- subject
-
- expect(last_alert_attributes).to match(
- project_id: project.id,
- title: payload_raw.fetch(:title),
- started_at: Time.zone.parse(payload_raw.fetch(:start_time)),
- severity: payload_raw.fetch(:severity),
- status: AlertManagement::Alert::STATUSES[:triggered],
- events: 1,
- hosts: payload_raw.fetch(:hosts),
- payload: payload_raw.with_indifferent_access,
- issue_id: nil,
- description: payload_raw.fetch(:description),
- monitoring_tool: payload_raw.fetch(:monitoring_tool),
- service: payload_raw.fetch(:service),
- fingerprint: Digest::SHA1.hexdigest(fingerprint),
- ended_at: nil
- )
- end
-
- it 'executes the alert service hooks' do
- slack_service = create(:service, type: 'SlackService', project: project, alert_events: true, active: true)
- subject
-
- expect(ProjectServiceWorker).to have_received(:perform_async).with(slack_service.id, an_instance_of(Hash))
- end
+ it_behaves_like 'creates an alert management alert'
+ it_behaves_like 'assigns the alert properties'
context 'existing alert with same fingerprint' do
let(:fingerprint_sha) { Digest::SHA1.hexdigest(fingerprint) }
- let!(:existing_alert) { create(:alert_management_alert, project: project, fingerprint: fingerprint_sha) }
+ let!(:alert) { create(:alert_management_alert, project: project, fingerprint: fingerprint_sha) }
+
+ it_behaves_like 'adds an alert management alert event'
+
+ context 'existing alert is resolved' do
+ let!(:alert) { create(:alert_management_alert, :resolved, project: project, fingerprint: fingerprint_sha) }
- it 'does not create AlertManagement::Alert' do
- expect { subject }.not_to change(AlertManagement::Alert, :count)
+ it_behaves_like 'creates an alert management alert'
+ it_behaves_like 'assigns the alert properties'
end
- it 'increments the existing alert count' do
- expect { subject }.to change { existing_alert.reload.events }.from(1).to(2)
+ context 'existing alert is ignored' do
+ let!(:alert) { create(:alert_management_alert, :ignored, project: project, fingerprint: fingerprint_sha) }
+
+ it_behaves_like 'adds an alert management alert event'
end
- it 'does not executes the alert service hooks' do
- subject
+ context 'two existing alerts, one resolved one open' do
+ let!(:resolved_existing_alert) { create(:alert_management_alert, :resolved, project: project, fingerprint: fingerprint_sha) }
+ let!(:alert) { create(:alert_management_alert, project: project, fingerprint: fingerprint_sha) }
- expect(ProjectServiceWorker).not_to have_received(:perform_async)
+ it_behaves_like 'adds an alert management alert event'
end
end
@@ -172,9 +170,7 @@ describe Projects::Alerting::NotifyService do
}
end
- it 'creates AlertManagement::Alert' do
- expect { subject }.to change(AlertManagement::Alert, :count).by(1)
- end
+ it_behaves_like 'creates an alert management alert'
it 'created alert has all data properly assigned' do
subject
@@ -193,7 +189,9 @@ describe Projects::Alerting::NotifyService do
monitoring_tool: nil,
service: nil,
fingerprint: nil,
- ended_at: nil
+ ended_at: nil,
+ prometheus_alert_id: nil,
+ environment_id: nil
)
end
end
@@ -214,19 +212,19 @@ describe Projects::Alerting::NotifyService do
end
it_behaves_like 'does not process incident issues due to error', http_status: :bad_request
- it_behaves_like 'NotifyService does not create alert'
+ it_behaves_like 'does not an create alert management alert'
end
context 'when alert already exists' do
let(:fingerprint_sha) { Digest::SHA1.hexdigest(fingerprint) }
- let!(:existing_alert) { create(:alert_management_alert, project: project, fingerprint: fingerprint_sha) }
+ let!(:alert) { create(:alert_management_alert, project: project, fingerprint: fingerprint_sha) }
context 'when existing alert does not have an associated issue' do
it_behaves_like 'processes incident issues'
end
context 'when existing alert has an associated issue' do
- let!(:existing_alert) { create(:alert_management_alert, :with_issue, project: project, fingerprint: fingerprint_sha) }
+ let!(:alert) { create(:alert_management_alert, :with_issue, project: project, fingerprint: fingerprint_sha) }
it_behaves_like 'does not process incident issues'
end
@@ -242,14 +240,14 @@ describe Projects::Alerting::NotifyService do
context 'with invalid token' do
it_behaves_like 'does not process incident issues due to error', http_status: :unauthorized
- it_behaves_like 'NotifyService does not create alert'
+ it_behaves_like 'does not an create alert management alert'
end
context 'with deactivated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, :inactive, project: project) }
it_behaves_like 'does not process incident issues due to error', http_status: :forbidden
- it_behaves_like 'NotifyService does not create alert'
+ it_behaves_like 'does not an create alert management alert'
end
end
end
diff --git a/spec/services/projects/auto_devops/disable_service_spec.rb b/spec/services/projects/auto_devops/disable_service_spec.rb
index fb1ab3f9949..1f161990fb2 100644
--- a/spec/services/projects/auto_devops/disable_service_spec.rb
+++ b/spec/services/projects/auto_devops/disable_service_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe Projects::AutoDevops::DisableService, '#execute' do
+RSpec.describe Projects::AutoDevops::DisableService, '#execute' do
let(:project) { create(:project, :repository, :auto_devops) }
let(:auto_devops) { project.auto_devops }
diff --git a/spec/services/projects/autocomplete_service_spec.rb b/spec/services/projects/autocomplete_service_spec.rb
index b625653bc77..336aa37096a 100644
--- a/spec/services/projects/autocomplete_service_spec.rb
+++ b/spec/services/projects/autocomplete_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::AutocompleteService do
+RSpec.describe Projects::AutocompleteService do
describe '#issues' do
describe 'confidential issues' do
let(:author) { create(:user) }
diff --git a/spec/services/projects/batch_open_issues_count_service_spec.rb b/spec/services/projects/batch_open_issues_count_service_spec.rb
index 8cb0ce03fba..82d50604309 100644
--- a/spec/services/projects/batch_open_issues_count_service_spec.rb
+++ b/spec/services/projects/batch_open_issues_count_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::BatchOpenIssuesCountService do
+RSpec.describe Projects::BatchOpenIssuesCountService do
let!(:project_1) { create(:project) }
let!(:project_2) { create(:project) }
diff --git a/spec/services/projects/cleanup_service_spec.rb b/spec/services/projects/cleanup_service_spec.rb
index 5c246854eb7..528f31456a9 100644
--- a/spec/services/projects/cleanup_service_spec.rb
+++ b/spec/services/projects/cleanup_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::CleanupService do
+RSpec.describe Projects::CleanupService do
let(:project) { create(:project, :repository, bfg_object_map: fixture_file_upload('spec/fixtures/bfg_object_map.txt')) }
let(:object_map) { project.bfg_object_map }
diff --git a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb
index 11ea7d51673..2c708e75a25 100644
--- a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb
+++ b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ContainerRepository::CleanupTagsService do
+RSpec.describe Projects::ContainerRepository::CleanupTagsService do
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project, :private) }
let_it_be(:repository) { create(:container_repository, :root, project: project) }
diff --git a/spec/services/projects/container_repository/delete_tags_service_spec.rb b/spec/services/projects/container_repository/delete_tags_service_spec.rb
index e17e4b6f7c9..3d065deefdf 100644
--- a/spec/services/projects/container_repository/delete_tags_service_spec.rb
+++ b/spec/services/projects/container_repository/delete_tags_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ContainerRepository::DeleteTagsService do
+RSpec.describe Projects::ContainerRepository::DeleteTagsService do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :private) }
let_it_be(:repository) { create(:container_repository, :root, project: project) }
@@ -20,6 +20,31 @@ describe Projects::ContainerRepository::DeleteTagsService do
tags: %w(latest A Ba Bb C D E))
end
+ RSpec.shared_examples 'logging a success response' do
+ it 'logs an info message' do
+ expect(service).to receive(:log_info).with(
+ service_class: 'Projects::ContainerRepository::DeleteTagsService',
+ message: 'deleted tags',
+ container_repository_id: repository.id,
+ deleted_tags_count: tags.size
+ )
+
+ subject
+ end
+ end
+
+ RSpec.shared_examples 'logging an error response' do |message: 'could not delete tags'|
+ it 'logs an error message' do
+ expect(service).to receive(:log_error).with(
+ service_class: 'Projects::ContainerRepository::DeleteTagsService',
+ message: message,
+ container_repository_id: repository.id
+ )
+
+ subject
+ end
+ end
+
describe '#execute' do
let(:tags) { %w[A] }
@@ -47,11 +72,8 @@ describe Projects::ContainerRepository::DeleteTagsService do
let_it_be(:tags) { %w[A Ba] }
it 'deletes the tags by name' do
- stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/A")
- .to_return(status: 200, body: "")
-
- stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/Ba")
- .to_return(status: 200, body: "")
+ stub_delete_reference_request('A')
+ stub_delete_reference_request('Ba')
expect_delete_tag_by_name('A')
expect_delete_tag_by_name('Ba')
@@ -60,26 +82,29 @@ describe Projects::ContainerRepository::DeleteTagsService do
end
it 'succeeds when tag delete returns 404' do
- stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/A")
- .to_return(status: 200, body: "")
-
- stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/Ba")
- .to_return(status: 404, body: "")
+ stub_delete_reference_request('A')
+ stub_delete_reference_request('Ba', 404)
is_expected.to include(status: :success)
end
+ it_behaves_like 'logging a success response' do
+ before do
+ stub_delete_reference_request('A')
+ stub_delete_reference_request('Ba')
+ end
+ end
+
context 'with failures' do
context 'when the delete request fails' do
before do
- stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/A")
- .to_return(status: 500, body: "")
-
- stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/Ba")
- .to_return(status: 500, body: "")
+ stub_delete_reference_request('A', 500)
+ stub_delete_reference_request('Ba', 500)
end
it { is_expected.to include(status: :error) }
+
+ it_behaves_like 'logging an error response'
end
end
end
@@ -104,19 +129,35 @@ describe Projects::ContainerRepository::DeleteTagsService do
end
end
end
+
context 'and the feature is disabled' do
+ let_it_be(:tags) { %w[A Ba] }
+
before do
stub_feature_flags(container_registry_fast_tag_delete: false)
+ stub_upload("{\n \"config\": {\n }\n}", 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
+ stub_put_manifest_request('A')
+ stub_put_manifest_request('Ba')
end
it 'fallbacks to slow delete' do
expect(service).not_to receive(:fast_delete)
- expect(service).to receive(:slow_delete).with(repository, tags)
+ expect(service).to receive(:slow_delete).with(repository, tags).and_call_original
+
+ expect_delete_tag_by_digest('sha256:dummy')
subject
end
+
+ it_behaves_like 'logging a success response' do
+ before do
+ allow(service).to receive(:slow_delete).and_call_original
+ expect_delete_tag_by_digest('sha256:dummy')
+ end
+ end
end
end
+
context 'when the registry does not support fast delete' do
let_it_be(:project) { create(:project, :private) }
let_it_be(:repository) { create(:container_repository, :root, project: project) }
@@ -155,11 +196,8 @@ describe Projects::ContainerRepository::DeleteTagsService do
it 'deletes the tags using a dummy image' do
stub_upload("{\n \"config\": {\n }\n}", 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
- stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/A")
- .to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
-
- stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/Ba")
- .to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
+ stub_put_manifest_request('A')
+ stub_put_manifest_request('Ba')
expect_delete_tag_by_digest('sha256:dummy')
@@ -169,11 +207,8 @@ describe Projects::ContainerRepository::DeleteTagsService do
it 'succeeds when tag delete returns 404' do
stub_upload("{\n \"config\": {\n }\n}", 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
- stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/A")
- .to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
-
- stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/Ba")
- .to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
+ stub_put_manifest_request('A')
+ stub_put_manifest_request('Ba')
stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/manifests/sha256:dummy")
.to_return(status: 404, body: "", headers: {})
@@ -181,6 +216,15 @@ describe Projects::ContainerRepository::DeleteTagsService do
is_expected.to include(status: :success)
end
+ it_behaves_like 'logging a success response' do
+ before do
+ stub_upload("{\n \"config\": {\n }\n}", 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
+ stub_put_manifest_request('A')
+ stub_put_manifest_request('Ba')
+ expect_delete_tag_by_digest('sha256:dummy')
+ end
+ end
+
context 'with failures' do
context 'when the dummy manifest generation fails' do
before do
@@ -188,23 +232,23 @@ describe Projects::ContainerRepository::DeleteTagsService do
end
it { is_expected.to include(status: :error) }
+
+ it_behaves_like 'logging an error response', message: 'could not generate manifest'
end
context 'when updating the tags fails' do
before do
stub_upload("{\n \"config\": {\n }\n}", 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
- stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/A")
- .to_return(status: 500, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
-
- stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/Ba")
- .to_return(status: 500, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
+ stub_put_manifest_request('A', 500)
+ stub_put_manifest_request('Ba', 500)
stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/manifests/sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3")
.to_return(status: 200, body: "", headers: {})
end
it { is_expected.to include(status: :error) }
+ it_behaves_like 'logging an error response'
end
end
end
@@ -214,6 +258,16 @@ describe Projects::ContainerRepository::DeleteTagsService do
private
+ def stub_delete_reference_request(tag, status = 200)
+ stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/#{tag}")
+ .to_return(status: status, body: '')
+ end
+
+ def stub_put_manifest_request(tag, status = 200, headers = { 'docker-content-digest' => 'sha256:dummy' })
+ stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/#{tag}")
+ .to_return(status: status, body: '', headers: headers)
+ end
+
def stub_tag_digest(tag, digest)
stub_request(:head, "http://registry.gitlab/v2/#{repository.path}/manifests/#{tag}")
.to_return(status: 200, body: "", headers: { 'docker-content-digest' => digest })
diff --git a/spec/services/projects/container_repository/destroy_service_spec.rb b/spec/services/projects/container_repository/destroy_service_spec.rb
index 753b7540d7f..20e75d94e05 100644
--- a/spec/services/projects/container_repository/destroy_service_spec.rb
+++ b/spec/services/projects/container_repository/destroy_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ContainerRepository::DestroyService do
+RSpec.describe Projects::ContainerRepository::DestroyService do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :private) }
diff --git a/spec/services/projects/count_service_spec.rb b/spec/services/projects/count_service_spec.rb
index e345b508f53..11b2b57a277 100644
--- a/spec/services/projects/count_service_spec.rb
+++ b/spec/services/projects/count_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::CountService do
+RSpec.describe Projects::CountService do
let(:project) { build(:project, id: 1) }
let(:service) { described_class.new(project) }
diff --git a/spec/services/projects/create_from_template_service_spec.rb b/spec/services/projects/create_from_template_service_spec.rb
index 0b4772e8f02..7e23daabcd3 100644
--- a/spec/services/projects/create_from_template_service_spec.rb
+++ b/spec/services/projects/create_from_template_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::CreateFromTemplateService do
+RSpec.describe Projects::CreateFromTemplateService do
let(:user) { create(:user) }
let(:template_name) { 'rails' }
let(:project_params) do
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index e70ee05ed31..9eb7cacbbcb 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::CreateService, '#execute' do
+RSpec.describe Projects::CreateService, '#execute' do
include ExternalAuthorizationServiceHelpers
include GitHelpers
@@ -240,13 +240,21 @@ describe Projects::CreateService, '#execute' do
end
context 'import data' do
- it 'stores import data and URL' do
- import_data = { data: { 'test' => 'some data' } }
- project = create_project(user, { name: 'test', import_url: 'http://import-url', import_data: import_data })
+ let(:import_data) { { data: { 'test' => 'some data' } } }
+ let(:imported_project) { create_project(user, { name: 'test', import_url: 'http://import-url', import_data: import_data }) }
+
+ it 'does not write repository config' do
+ expect_next_instance_of(Project) do |project|
+ expect(project).not_to receive(:write_repository_config)
+ end
- expect(project.import_data).to be_persisted
- expect(project.import_data.data).to eq(import_data[:data])
- expect(project.import_url).to eq('http://import-url')
+ imported_project
+ end
+
+ it 'stores import data and URL' do
+ expect(imported_project.import_data).to be_persisted
+ expect(imported_project.import_data.data).to eq(import_data[:data])
+ expect(imported_project.import_url).to eq('http://import-url')
end
end
@@ -438,14 +446,35 @@ describe Projects::CreateService, '#execute' do
end
context 'when readme initialization is requested' do
- it 'creates README.md' do
+ let(:project) { create_project(user, opts) }
+
+ before do
opts[:initialize_with_readme] = '1'
+ end
- project = create_project(user, opts)
+ shared_examples 'creates README.md' do
+ it { expect(project.repository.commit_count).to be(1) }
+ it { expect(project.repository.readme.name).to eql('README.md') }
+ it { expect(project.repository.readme.data).to include('# GitLab') }
+ end
- expect(project.repository.commit_count).to be(1)
- expect(project.repository.readme.name).to eql('README.md')
- expect(project.repository.readme.data).to include('# GitLab')
+ it_behaves_like 'creates README.md'
+
+ context 'and a default_branch_name is specified' do
+ before do
+ allow(Gitlab::CurrentSettings)
+ .to receive(:default_branch_name)
+ .and_return('example_branch')
+ end
+
+ it_behaves_like 'creates README.md'
+
+ it 'creates README.md within the specified branch rather than master' do
+ branches = project.repository.branches
+
+ expect(branches.size).to eq(1)
+ expect(branches.collect(&:name)).to contain_exactly('example_branch')
+ end
end
end
@@ -647,10 +676,6 @@ describe Projects::CreateService, '#execute' do
end
it 'updates authorization for current_user' do
- expect(Users::RefreshAuthorizedProjectsService).to(
- receive(:new).with(user).and_call_original
- )
-
project = create_project(user, opts)
expect(
@@ -682,10 +707,6 @@ describe Projects::CreateService, '#execute' do
end
it 'updates authorization for current_user' do
- expect(Users::RefreshAuthorizedProjectsService).to(
- receive(:new).with(user).and_call_original
- )
-
project = create_project(user, opts)
expect(
diff --git a/spec/services/projects/deploy_tokens/create_service_spec.rb b/spec/services/projects/deploy_tokens/create_service_spec.rb
index 5c3ada8af4e..831dbc06588 100644
--- a/spec/services/projects/deploy_tokens/create_service_spec.rb
+++ b/spec/services/projects/deploy_tokens/create_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::DeployTokens::CreateService do
+RSpec.describe Projects::DeployTokens::CreateService do
it_behaves_like 'a deploy token creation service' do
let(:entity) { create(:project) }
let(:deploy_token_class) { ProjectDeployToken }
diff --git a/spec/services/projects/deploy_tokens/destroy_service_spec.rb b/spec/services/projects/deploy_tokens/destroy_service_spec.rb
index 24407f46615..edb2345aa6c 100644
--- a/spec/services/projects/deploy_tokens/destroy_service_spec.rb
+++ b/spec/services/projects/deploy_tokens/destroy_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::DeployTokens::DestroyService do
+RSpec.describe Projects::DeployTokens::DestroyService do
it_behaves_like 'a deploy token deletion service' do
let_it_be(:entity) { create(:project) }
let_it_be(:deploy_token_class) { ProjectDeployToken }
diff --git a/spec/services/projects/destroy_rollback_service_spec.rb b/spec/services/projects/destroy_rollback_service_spec.rb
index 8facf17dc45..f63939337b8 100644
--- a/spec/services/projects/destroy_rollback_service_spec.rb
+++ b/spec/services/projects/destroy_rollback_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::DestroyRollbackService do
+RSpec.describe Projects::DestroyRollbackService do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, namespace: user.namespace) }
let(:repository) { project.repository }
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb
index 58c40d04fe9..56b19c33ece 100644
--- a/spec/services/projects/destroy_service_spec.rb
+++ b/spec/services/projects/destroy_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::DestroyService do
+RSpec.describe Projects::DestroyService do
include ProjectForksHelper
let_it_be(:user) { create(:user) }
diff --git a/spec/services/projects/detect_repository_languages_service_spec.rb b/spec/services/projects/detect_repository_languages_service_spec.rb
index 76600b0e77c..cf4c7a5024d 100644
--- a/spec/services/projects/detect_repository_languages_service_spec.rb
+++ b/spec/services/projects/detect_repository_languages_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::DetectRepositoryLanguagesService, :clean_gitlab_redis_shared_state do
+RSpec.describe Projects::DetectRepositoryLanguagesService, :clean_gitlab_redis_shared_state do
let_it_be(:project, reload: true) { create(:project, :repository) }
subject { described_class.new(project) }
diff --git a/spec/services/projects/download_service_spec.rb b/spec/services/projects/download_service_spec.rb
index 06efc2ff825..0f743eaa7f5 100644
--- a/spec/services/projects/download_service_spec.rb
+++ b/spec/services/projects/download_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::DownloadService do
+RSpec.describe Projects::DownloadService do
describe 'File service' do
before do
@user = create(:user)
diff --git a/spec/services/projects/enable_deploy_key_service_spec.rb b/spec/services/projects/enable_deploy_key_service_spec.rb
index 64de373d7f6..f297ec374cf 100644
--- a/spec/services/projects/enable_deploy_key_service_spec.rb
+++ b/spec/services/projects/enable_deploy_key_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::EnableDeployKeyService do
+RSpec.describe Projects::EnableDeployKeyService do
let(:deploy_key) { create(:deploy_key, public: true) }
let(:project) { create(:project) }
let(:user) { project.creator}
diff --git a/spec/services/projects/fetch_statistics_increment_service_spec.rb b/spec/services/projects/fetch_statistics_increment_service_spec.rb
index fcfb138aad6..16121a42c39 100644
--- a/spec/services/projects/fetch_statistics_increment_service_spec.rb
+++ b/spec/services/projects/fetch_statistics_increment_service_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
module Projects
- describe FetchStatisticsIncrementService do
+ RSpec.describe FetchStatisticsIncrementService do
let(:project) { create(:project) }
describe '#execute' do
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index 112a41c773b..c49aa42b147 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ForkService do
+RSpec.describe Projects::ForkService do
include ProjectForksHelper
shared_examples 'forks count cache refresh' do
@@ -10,6 +10,7 @@ describe Projects::ForkService do
expect(from_project.forks_count).to be_zero
fork_project(from_project, to_user)
+ BatchLoader::Executor.clear_current
expect(from_project.forks_count).to eq(1)
end
@@ -327,7 +328,7 @@ describe Projects::ForkService do
destination_storage_name: 'test_second_storage'
)
Projects::UpdateRepositoryStorageService.new(storage_move).execute
- fork_after_move = fork_project(project)
+ fork_after_move = fork_project(project.reload)
pool_repository_before_move = PoolRepository.joins(:shard)
.find_by(source_project: project, shards: { name: 'default' })
pool_repository_after_move = PoolRepository.joins(:shard)
@@ -405,6 +406,7 @@ describe Projects::ForkService do
expect(fork_from_project.forks_count).to be_zero
subject.execute(fork_to_project)
+ BatchLoader::Executor.clear_current
expect(fork_from_project.forks_count).to eq(1)
end
diff --git a/spec/services/projects/forks_count_service_spec.rb b/spec/services/projects/forks_count_service_spec.rb
index 21a75eafc7a..31662f78973 100644
--- a/spec/services/projects/forks_count_service_spec.rb
+++ b/spec/services/projects/forks_count_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ForksCountService, :use_clean_rails_memory_store_caching do
+RSpec.describe Projects::ForksCountService, :use_clean_rails_memory_store_caching do
let(:project) { build(:project) }
subject { described_class.new(project) }
diff --git a/spec/services/projects/git_deduplication_service_spec.rb b/spec/services/projects/git_deduplication_service_spec.rb
index 9e6279da7de..b98db5bc41b 100644
--- a/spec/services/projects/git_deduplication_service_spec.rb
+++ b/spec/services/projects/git_deduplication_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::GitDeduplicationService do
+RSpec.describe Projects::GitDeduplicationService do
include ExclusiveLeaseHelpers
let(:pool) { create(:pool_repository, :ready) }
@@ -139,7 +139,7 @@ describe Projects::GitDeduplicationService do
end
it 'fails when a lease is already out' do
- expect(service).to receive(:log_error).with('Cannot obtain an exclusive lease. There must be another instance already in execution.')
+ expect(service).to receive(:log_error).with("Cannot obtain an exclusive lease for #{service.class.name}. There must be another instance already in execution.")
service.execute
end
diff --git a/spec/services/projects/gitlab_projects_import_service_spec.rb b/spec/services/projects/gitlab_projects_import_service_spec.rb
index 1662d4577aa..09d093a9916 100644
--- a/spec/services/projects/gitlab_projects_import_service_spec.rb
+++ b/spec/services/projects/gitlab_projects_import_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::GitlabProjectsImportService do
+RSpec.describe Projects::GitlabProjectsImportService do
let_it_be(:namespace) { create(:namespace) }
let(:path) { 'test-path' }
let(:file) { fixture_file_upload('spec/fixtures/project_export.tar.gz') }
diff --git a/spec/services/projects/group_links/create_service_spec.rb b/spec/services/projects/group_links/create_service_spec.rb
index 22f7c8bdcb4..6468e3007c2 100644
--- a/spec/services/projects/group_links/create_service_spec.rb
+++ b/spec/services/projects/group_links/create_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::GroupLinks::CreateService, '#execute' do
+RSpec.describe Projects::GroupLinks::CreateService, '#execute' do
let_it_be(:user) { create :user }
let_it_be(:group) { create :group }
let_it_be(:project) { create :project }
@@ -23,7 +23,7 @@ describe Projects::GroupLinks::CreateService, '#execute' do
expect { subject.execute(group) }.to change { project.project_group_links.count }.from(0).to(1)
end
- it 'updates authorization' do
+ it 'updates authorization', :sidekiq_inline do
expect { subject.execute(group) }.to(
change { Ability.allowed?(user, :read_project, project) }
.from(false).to(true))
@@ -36,4 +36,50 @@ describe Projects::GroupLinks::CreateService, '#execute' do
it 'returns error if user is not allowed to share with a group' do
expect { subject.execute(create(:group)) }.not_to change { project.project_group_links.count }
end
+
+ context 'with specialized_project_authorization_workers' do
+ let_it_be(:other_user) { create(:user) }
+
+ before do
+ group.add_developer(other_user)
+ end
+
+ it 'schedules authorization update for users with access to group' do
+ expect(AuthorizedProjectsWorker).not_to(
+ receive(:bulk_perform_async)
+ )
+ expect(AuthorizedProjectUpdate::ProjectGroupLinkCreateWorker).to(
+ receive(:perform_async).and_call_original
+ )
+ expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).to(
+ receive(:bulk_perform_in)
+ .with(1.hour,
+ array_including([user.id], [other_user.id]),
+ batch_delay: 30.seconds, batch_size: 100)
+ .and_call_original
+ )
+
+ subject.execute(group)
+ end
+
+ context 'when feature is disabled' do
+ before do
+ stub_feature_flags(specialized_project_authorization_project_share_worker: false)
+ end
+
+ it 'uses AuthorizedProjectsWorker' do
+ expect(AuthorizedProjectsWorker).to(
+ receive(:bulk_perform_async).with(array_including([user.id], [other_user.id])).and_call_original
+ )
+ expect(AuthorizedProjectUpdate::ProjectCreateWorker).not_to(
+ receive(:perform_async)
+ )
+ expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).not_to(
+ receive(:bulk_perform_in)
+ )
+
+ subject.execute(group)
+ end
+ end
+ end
end
diff --git a/spec/services/projects/group_links/destroy_service_spec.rb b/spec/services/projects/group_links/destroy_service_spec.rb
index 0a8c9580e70..459b79b2d7d 100644
--- a/spec/services/projects/group_links/destroy_service_spec.rb
+++ b/spec/services/projects/group_links/destroy_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::GroupLinks::DestroyService, '#execute' do
+RSpec.describe Projects::GroupLinks::DestroyService, '#execute' do
let_it_be(:user) { create :user }
let_it_be(:project) { create(:project, :private) }
let_it_be(:group) { create(:group) }
diff --git a/spec/services/projects/group_links/update_service_spec.rb b/spec/services/projects/group_links/update_service_spec.rb
index 5be2ae1e0f7..053c5eb611e 100644
--- a/spec/services/projects/group_links/update_service_spec.rb
+++ b/spec/services/projects/group_links/update_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::GroupLinks::UpdateService, '#execute' do
+RSpec.describe Projects::GroupLinks::UpdateService, '#execute' do
let_it_be(:user) { create :user }
let_it_be(:group) { create :group }
let_it_be(:project) { create :project }
diff --git a/spec/services/projects/hashed_storage/base_attachment_service_spec.rb b/spec/services/projects/hashed_storage/base_attachment_service_spec.rb
index 070dd5fc1b8..5e1b6f2e404 100644
--- a/spec/services/projects/hashed_storage/base_attachment_service_spec.rb
+++ b/spec/services/projects/hashed_storage/base_attachment_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HashedStorage::BaseAttachmentService do
+RSpec.describe Projects::HashedStorage::BaseAttachmentService do
let(:project) { create(:project, :repository, storage_version: 0, skip_disk_validation: true) }
subject(:service) { described_class.new(project: project, old_disk_path: project.full_path, logger: nil) }
diff --git a/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb b/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb
index 7c7e188a12d..c8f24c6ce00 100644
--- a/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb
+++ b/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HashedStorage::MigrateAttachmentsService do
+RSpec.describe Projects::HashedStorage::MigrateAttachmentsService do
subject(:service) { described_class.new(project: project, old_disk_path: project.full_path, logger: nil) }
let(:project) { create(:project, :repository, storage_version: 1, skip_disk_validation: true) }
diff --git a/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb b/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb
index f1eaf8324e0..e03e75653ff 100644
--- a/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb
+++ b/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HashedStorage::MigrateRepositoryService do
+RSpec.describe Projects::HashedStorage::MigrateRepositoryService do
include GitHelpers
let(:gitlab_shell) { Gitlab::Shell.new }
diff --git a/spec/services/projects/hashed_storage/migration_service_spec.rb b/spec/services/projects/hashed_storage/migration_service_spec.rb
index 0a7975305dc..ef96c17dd85 100644
--- a/spec/services/projects/hashed_storage/migration_service_spec.rb
+++ b/spec/services/projects/hashed_storage/migration_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HashedStorage::MigrationService do
+RSpec.describe Projects::HashedStorage::MigrationService do
let(:project) { create(:project, :empty_repo, :wiki_repo, :legacy_storage) }
let(:logger) { double }
let!(:project_attachment) { build(:file_uploader, project: project) }
diff --git a/spec/services/projects/hashed_storage/rollback_attachments_service_spec.rb b/spec/services/projects/hashed_storage/rollback_attachments_service_spec.rb
index 54695e6e48f..d4cb46c82ad 100644
--- a/spec/services/projects/hashed_storage/rollback_attachments_service_spec.rb
+++ b/spec/services/projects/hashed_storage/rollback_attachments_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HashedStorage::RollbackAttachmentsService do
+RSpec.describe Projects::HashedStorage::RollbackAttachmentsService do
subject(:service) { described_class.new(project: project, old_disk_path: project.disk_path, logger: nil) }
let(:project) { create(:project, :repository, skip_disk_validation: true) }
diff --git a/spec/services/projects/hashed_storage/rollback_repository_service_spec.rb b/spec/services/projects/hashed_storage/rollback_repository_service_spec.rb
index 1c0f446d9cf..f2b1ce30a54 100644
--- a/spec/services/projects/hashed_storage/rollback_repository_service_spec.rb
+++ b/spec/services/projects/hashed_storage/rollback_repository_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HashedStorage::RollbackRepositoryService, :clean_gitlab_redis_shared_state do
+RSpec.describe Projects::HashedStorage::RollbackRepositoryService, :clean_gitlab_redis_shared_state do
include GitHelpers
let(:gitlab_shell) { Gitlab::Shell.new }
diff --git a/spec/services/projects/hashed_storage/rollback_service_spec.rb b/spec/services/projects/hashed_storage/rollback_service_spec.rb
index e6b7daba99e..0bd63f2da2a 100644
--- a/spec/services/projects/hashed_storage/rollback_service_spec.rb
+++ b/spec/services/projects/hashed_storage/rollback_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HashedStorage::RollbackService do
+RSpec.describe Projects::HashedStorage::RollbackService do
let(:project) { create(:project, :empty_repo, :wiki_repo) }
let(:logger) { double }
let!(:project_attachment) { build(:file_uploader, project: project) }
diff --git a/spec/services/projects/housekeeping_service_spec.rb b/spec/services/projects/housekeeping_service_spec.rb
index 98a27a71c26..18871f010f8 100644
--- a/spec/services/projects/housekeeping_service_spec.rb
+++ b/spec/services/projects/housekeeping_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::HousekeepingService do
+RSpec.describe Projects::HousekeepingService do
subject { described_class.new(project) }
let_it_be(:project) { create(:project, :repository) }
diff --git a/spec/services/projects/import_error_filter_spec.rb b/spec/services/projects/import_error_filter_spec.rb
index 312b658de89..fd31cd52cc4 100644
--- a/spec/services/projects/import_error_filter_spec.rb
+++ b/spec/services/projects/import_error_filter_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ImportErrorFilter do
+RSpec.describe Projects::ImportErrorFilter do
it 'filters any full paths' do
message = 'Error importing into /my/folder Permission denied @ unlink_internal - /var/opt/gitlab/gitlab-rails/shared/a/b/c/uploads/file'
diff --git a/spec/services/projects/import_export/export_service_spec.rb b/spec/services/projects/import_export/export_service_spec.rb
index 19891341311..111c1264777 100644
--- a/spec/services/projects/import_export/export_service_spec.rb
+++ b/spec/services/projects/import_export/export_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ImportExport::ExportService do
+RSpec.describe Projects::ImportExport::ExportService do
describe '#execute' do
let!(:user) { create(:user) }
let(:project) { create(:project) }
diff --git a/spec/services/projects/import_service_spec.rb b/spec/services/projects/import_service_spec.rb
index ca6750b373d..92e18b6cb46 100644
--- a/spec/services/projects/import_service_spec.rb
+++ b/spec/services/projects/import_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ImportService do
+RSpec.describe Projects::ImportService do
let!(:project) { create(:project) }
let(:user) { project.creator }
diff --git a/spec/services/projects/lfs_pointers/lfs_download_link_list_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_download_link_list_service_spec.rb
index 99d35fdc7f7..66a450bd734 100644
--- a/spec/services/projects/lfs_pointers/lfs_download_link_list_service_spec.rb
+++ b/spec/services/projects/lfs_pointers/lfs_download_link_list_service_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe Projects::LfsPointers::LfsDownloadLinkListService do
+RSpec.describe Projects::LfsPointers::LfsDownloadLinkListService do
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
let(:lfs_endpoint) { "#{import_url}/info/lfs/objects/batch" }
let!(:project) { create(:project, import_url: import_url) }
diff --git a/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb
index 496d1fe67f2..a606371099d 100644
--- a/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb
+++ b/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe Projects::LfsPointers::LfsDownloadService do
+RSpec.describe Projects::LfsPointers::LfsDownloadService do
include StubRequests
let(:project) { create(:project) }
diff --git a/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb
index 016028a96bf..b36b0b8d6b2 100644
--- a/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb
+++ b/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe Projects::LfsPointers::LfsImportService do
+RSpec.describe Projects::LfsPointers::LfsImportService do
let(:project) { create(:project) }
let(:user) { project.creator }
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
diff --git a/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
index b64662f3782..d59f5dbae19 100644
--- a/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
+++ b/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe Projects::LfsPointers::LfsLinkService do
+RSpec.describe Projects::LfsPointers::LfsLinkService do
let!(:project) { create(:project, lfs_enabled: true) }
let!(:lfs_objects_project) { create_list(:lfs_objects_project, 2, project: project) }
let(:new_oids) { { 'oid1' => 123, 'oid2' => 125 } }
diff --git a/spec/services/projects/lfs_pointers/lfs_object_download_list_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_object_download_list_service_spec.rb
index e94d8a85987..0799a33f856 100644
--- a/spec/services/projects/lfs_pointers/lfs_object_download_list_service_spec.rb
+++ b/spec/services/projects/lfs_pointers/lfs_object_download_list_service_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe Projects::LfsPointers::LfsObjectDownloadListService do
+RSpec.describe Projects::LfsPointers::LfsObjectDownloadListService do
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
let(:default_endpoint) { "#{import_url}/info/lfs/objects/batch"}
let(:group) { create(:group, lfs_enabled: true)}
diff --git a/spec/services/projects/move_access_service_spec.rb b/spec/services/projects/move_access_service_spec.rb
index efa34c84522..de3871414af 100644
--- a/spec/services/projects/move_access_service_spec.rb
+++ b/spec/services/projects/move_access_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveAccessService do
+RSpec.describe Projects::MoveAccessService do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project_with_access) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/move_deploy_keys_projects_service_spec.rb b/spec/services/projects/move_deploy_keys_projects_service_spec.rb
index a5d28fb0fbf..e69b4dd4fc7 100644
--- a/spec/services/projects/move_deploy_keys_projects_service_spec.rb
+++ b/spec/services/projects/move_deploy_keys_projects_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveDeployKeysProjectsService do
+RSpec.describe Projects::MoveDeployKeysProjectsService do
let!(:user) { create(:user) }
let!(:project_with_deploy_keys) { create(:project, namespace: user.namespace) }
let!(:target_project) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/move_forks_service_spec.rb b/spec/services/projects/move_forks_service_spec.rb
index 8f9f048d5ff..7d3637b7758 100644
--- a/spec/services/projects/move_forks_service_spec.rb
+++ b/spec/services/projects/move_forks_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveForksService do
+RSpec.describe Projects::MoveForksService do
include ProjectForksHelper
let!(:user) { create(:user) }
diff --git a/spec/services/projects/move_lfs_objects_projects_service_spec.rb b/spec/services/projects/move_lfs_objects_projects_service_spec.rb
index 114509229c5..b73286fba9a 100644
--- a/spec/services/projects/move_lfs_objects_projects_service_spec.rb
+++ b/spec/services/projects/move_lfs_objects_projects_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveLfsObjectsProjectsService do
+RSpec.describe Projects::MoveLfsObjectsProjectsService do
let!(:user) { create(:user) }
let!(:project_with_lfs_objects) { create(:project, namespace: user.namespace) }
let!(:target_project) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/move_notification_settings_service_spec.rb b/spec/services/projects/move_notification_settings_service_spec.rb
index 54d85404bf6..7c9f1dd30d2 100644
--- a/spec/services/projects/move_notification_settings_service_spec.rb
+++ b/spec/services/projects/move_notification_settings_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveNotificationSettingsService do
+RSpec.describe Projects::MoveNotificationSettingsService do
let(:user) { create(:user) }
let(:project_with_notifications) { create(:project, namespace: user.namespace) }
let(:target_project) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/move_project_authorizations_service_spec.rb b/spec/services/projects/move_project_authorizations_service_spec.rb
index fe3ba31c881..a37b4d807a0 100644
--- a/spec/services/projects/move_project_authorizations_service_spec.rb
+++ b/spec/services/projects/move_project_authorizations_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveProjectAuthorizationsService do
+RSpec.describe Projects::MoveProjectAuthorizationsService do
let!(:user) { create(:user) }
let(:project_with_users) { create(:project, namespace: user.namespace) }
let(:target_project) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/move_project_group_links_service_spec.rb b/spec/services/projects/move_project_group_links_service_spec.rb
index 6140d679929..196a8f2b339 100644
--- a/spec/services/projects/move_project_group_links_service_spec.rb
+++ b/spec/services/projects/move_project_group_links_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveProjectGroupLinksService do
+RSpec.describe Projects::MoveProjectGroupLinksService do
let!(:user) { create(:user) }
let(:project_with_groups) { create(:project, namespace: user.namespace) }
let(:target_project) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/move_project_members_service_spec.rb b/spec/services/projects/move_project_members_service_spec.rb
index bdd5cd6a87a..f14f00e3866 100644
--- a/spec/services/projects/move_project_members_service_spec.rb
+++ b/spec/services/projects/move_project_members_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveProjectMembersService do
+RSpec.describe Projects::MoveProjectMembersService do
let!(:user) { create(:user) }
let(:project_with_users) { create(:project, namespace: user.namespace) }
let(:target_project) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/move_users_star_projects_service_spec.rb b/spec/services/projects/move_users_star_projects_service_spec.rb
index cde188f9f5f..0f766ebd0ec 100644
--- a/spec/services/projects/move_users_star_projects_service_spec.rb
+++ b/spec/services/projects/move_users_star_projects_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::MoveUsersStarProjectsService do
+RSpec.describe Projects::MoveUsersStarProjectsService do
let!(:user) { create(:user) }
let!(:project_with_stars) { create(:project, namespace: user.namespace) }
let!(:target_project) { create(:project, namespace: user.namespace) }
diff --git a/spec/services/projects/open_issues_count_service_spec.rb b/spec/services/projects/open_issues_count_service_spec.rb
index c1d49befeb9..c739fea5ecf 100644
--- a/spec/services/projects/open_issues_count_service_spec.rb
+++ b/spec/services/projects/open_issues_count_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::OpenIssuesCountService, :use_clean_rails_memory_store_caching do
+RSpec.describe Projects::OpenIssuesCountService, :use_clean_rails_memory_store_caching do
let(:project) { create(:project) }
subject { described_class.new(project) }
diff --git a/spec/services/projects/open_merge_requests_count_service_spec.rb b/spec/services/projects/open_merge_requests_count_service_spec.rb
index 7d848f9f2c3..6caef181e77 100644
--- a/spec/services/projects/open_merge_requests_count_service_spec.rb
+++ b/spec/services/projects/open_merge_requests_count_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::OpenMergeRequestsCountService, :use_clean_rails_memory_store_caching do
+RSpec.describe Projects::OpenMergeRequestsCountService, :use_clean_rails_memory_store_caching do
let_it_be(:project) { create(:project) }
subject { described_class.new(project) }
diff --git a/spec/services/projects/operations/update_service_spec.rb b/spec/services/projects/operations/update_service_spec.rb
index f4d62b48fe5..3cfc9844d65 100644
--- a/spec/services/projects/operations/update_service_spec.rb
+++ b/spec/services/projects/operations/update_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Operations::UpdateService do
+RSpec.describe Projects::Operations::UpdateService do
let_it_be(:user) { create(:user) }
let_it_be(:project, refind: true) { create(:project) }
diff --git a/spec/services/projects/overwrite_project_service_spec.rb b/spec/services/projects/overwrite_project_service_spec.rb
index def39ad3789..e4495da9807 100644
--- a/spec/services/projects/overwrite_project_service_spec.rb
+++ b/spec/services/projects/overwrite_project_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::OverwriteProjectService do
+RSpec.describe Projects::OverwriteProjectService do
include ProjectForksHelper
let(:user) { create(:user) }
diff --git a/spec/services/projects/participants_service_spec.rb b/spec/services/projects/participants_service_spec.rb
index f4a04159db4..33a3e37a2d2 100644
--- a/spec/services/projects/participants_service_spec.rb
+++ b/spec/services/projects/participants_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ParticipantsService do
+RSpec.describe Projects::ParticipantsService do
describe '#groups' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
diff --git a/spec/services/projects/prometheus/alerts/create_events_service_spec.rb b/spec/services/projects/prometheus/alerts/create_events_service_spec.rb
deleted file mode 100644
index 61236b5bbdb..00000000000
--- a/spec/services/projects/prometheus/alerts/create_events_service_spec.rb
+++ /dev/null
@@ -1,312 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-describe Projects::Prometheus::Alerts::CreateEventsService do
- let(:user) { create(:user) }
- let_it_be(:project) { create(:project) }
- let(:metric) { create(:prometheus_metric, project: project) }
- let(:service) { described_class.new(project, user, alerts_payload) }
-
- shared_examples 'events persisted' do |expected_count|
- subject { service.execute }
-
- it 'returns proper amount of created events' do
- expect(subject.size).to eq(expected_count)
- end
-
- it 'increments event count' do
- expect { subject }.to change { PrometheusAlertEvent.count }.to(expected_count)
- end
- end
-
- shared_examples 'no events persisted' do
- subject { service.execute }
-
- it 'returns no created events' do
- expect(subject).to be_empty
- end
-
- it 'does not change event count' do
- expect { subject }.not_to change { PrometheusAlertEvent.count }
- end
- end
-
- shared_examples 'self managed events persisted' do
- subject { service.execute }
-
- it 'returns created events' do
- expect(subject).not_to be_empty
- end
-
- it 'does change self managed event count' do
- expect { subject }.to change { SelfManagedPrometheusAlertEvent.count }
- end
- end
-
- context 'with valid alerts_payload' do
- let!(:alert) { create(:prometheus_alert, prometheus_metric: metric, project: project) }
-
- let(:events) { service.execute }
-
- context 'with a firing payload' do
- let(:started_at) { truncate_to_second(Time.current) }
- let(:firing_event) { alert_payload(status: 'firing', started_at: started_at) }
- let(:alerts_payload) { { 'alerts' => [firing_event] } }
-
- it_behaves_like 'events persisted', 1
-
- it 'returns created event' do
- event = events.first
-
- expect(event).to be_firing
- expect(event.started_at).to eq(started_at)
- expect(event.ended_at).to be_nil
- end
-
- context 'with 2 different firing events' do
- let(:another_firing_event) { alert_payload(status: 'firing', started_at: started_at + 1) }
- let(:alerts_payload) { { 'alerts' => [firing_event, another_firing_event] } }
-
- it_behaves_like 'events persisted', 2
- end
-
- context 'with already persisted firing event' do
- before do
- service.execute
- end
-
- it_behaves_like 'no events persisted'
- end
-
- context 'with duplicate payload' do
- let(:alerts_payload) { { 'alerts' => [firing_event, firing_event] } }
-
- it_behaves_like 'events persisted', 1
- end
- end
-
- context 'with a resolved payload' do
- let(:started_at) { truncate_to_second(Time.current) }
- let(:ended_at) { started_at + 1 }
- let(:resolved_event) { alert_payload(status: 'resolved', started_at: started_at, ended_at: ended_at) }
- let(:alerts_payload) { { 'alerts' => [resolved_event] } }
- let(:payload_key) { Gitlab::Alerting::Alert.new(project: project, payload: resolved_event).gitlab_fingerprint }
-
- context 'with a matching firing event' do
- before do
- create(:prometheus_alert_event,
- prometheus_alert: alert,
- payload_key: payload_key,
- started_at: started_at)
- end
-
- it 'does not create an additional event' do
- expect { service.execute }.not_to change { PrometheusAlertEvent.count }
- end
-
- it 'marks firing event as `resolved`' do
- expect(events.size).to eq(1)
-
- event = events.first
- expect(event).to be_resolved
- expect(event.started_at).to eq(started_at)
- expect(event.ended_at).to eq(ended_at)
- end
-
- context 'with duplicate payload' do
- let(:alerts_payload) { { 'alerts' => [resolved_event, resolved_event] } }
-
- it 'does not create an additional event' do
- expect { service.execute }.not_to change { PrometheusAlertEvent.count }
- end
-
- it 'marks firing event as `resolved` only once' do
- expect(events.size).to eq(1)
- end
- end
- end
-
- context 'without a matching firing event' do
- context 'due to payload_key' do
- let(:payload_key) { 'some other payload_key' }
-
- before do
- create(:prometheus_alert_event,
- prometheus_alert: alert,
- payload_key: payload_key,
- started_at: started_at)
- end
-
- it_behaves_like 'no events persisted'
- end
-
- context 'due to status' do
- before do
- create(:prometheus_alert_event, :resolved,
- prometheus_alert: alert,
- started_at: started_at)
- end
-
- it_behaves_like 'no events persisted'
- end
- end
-
- context 'with already resolved event' do
- before do
- service.execute
- end
-
- it_behaves_like 'no events persisted'
- end
- end
-
- context 'with a metric from another project' do
- let(:another_project) { create(:project) }
- let(:metric) { create(:prometheus_metric, project: another_project) }
- let(:alerts_payload) { { 'alerts' => [alert_payload] } }
-
- let!(:alert) do
- create(:prometheus_alert,
- prometheus_metric: metric,
- project: another_project)
- end
-
- it_behaves_like 'no events persisted'
- end
- end
-
- context 'with invalid payload' do
- let(:alert) { create(:prometheus_alert, prometheus_metric: metric, project: project) }
-
- describe '`alerts` key' do
- context 'is missing' do
- let(:alerts_payload) { {} }
-
- it_behaves_like 'no events persisted'
- end
-
- context 'is nil' do
- let(:alerts_payload) { { 'alerts' => nil } }
-
- it_behaves_like 'no events persisted'
- end
-
- context 'is empty' do
- let(:alerts_payload) { { 'alerts' => [] } }
-
- it_behaves_like 'no events persisted'
- end
-
- context 'is not a Hash' do
- let(:alerts_payload) { { 'alerts' => [:not_a_hash] } }
-
- it_behaves_like 'no events persisted'
- end
-
- describe '`status`' do
- context 'is missing' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(status: nil)] } }
-
- it_behaves_like 'no events persisted'
- end
-
- context 'is invalid' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(status: 'invalid')] } }
-
- it_behaves_like 'no events persisted'
- end
- end
-
- describe '`started_at`' do
- context 'is missing' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(started_at: nil)] } }
-
- it_behaves_like 'no events persisted'
- end
-
- context 'is invalid' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(started_at: 'invalid date')] } }
-
- it_behaves_like 'no events persisted'
- end
- end
-
- describe '`ended_at`' do
- context 'is missing and status is resolved' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(ended_at: nil, status: 'resolved')] } }
-
- it_behaves_like 'no events persisted'
- end
-
- context 'is invalid and status is resolved' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(ended_at: 'invalid date', status: 'resolved')] } }
-
- it_behaves_like 'no events persisted'
- end
- end
-
- describe '`labels`' do
- describe '`gitlab_alert_id`' do
- context 'is missing' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(gitlab_alert_id: nil)] } }
-
- it_behaves_like 'no events persisted'
- end
-
- context 'is missing but title is given' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(gitlab_alert_id: nil, title: 'alert')] } }
-
- it_behaves_like 'self managed events persisted'
- end
-
- context 'is missing and environment name is given' do
- let(:environment) { create(:environment, project: project) }
- let(:alerts_payload) { { 'alerts' => [alert_payload(gitlab_alert_id: nil, title: 'alert', environment: environment.name)] } }
-
- it_behaves_like 'self managed events persisted'
-
- it 'associates the environment to the alert event' do
- service.execute
-
- expect(SelfManagedPrometheusAlertEvent.last.environment).to eq environment
- end
- end
-
- context 'is invalid' do
- let(:alerts_payload) { { 'alerts' => [alert_payload(gitlab_alert_id: '-1')] } }
-
- it_behaves_like 'no events persisted'
- end
- end
- end
- end
- end
-
- private
-
- def alert_payload(status: 'firing', started_at: Time.current, ended_at: Time.current, gitlab_alert_id: alert.prometheus_metric_id, title: nil, environment: nil)
- payload = {}
-
- payload['status'] = status if status
- payload['startsAt'] = utc_rfc3339(started_at) if started_at
- payload['endsAt'] = utc_rfc3339(ended_at) if ended_at
- payload['labels'] = {}
- payload['labels']['gitlab_alert_id'] = gitlab_alert_id.to_s if gitlab_alert_id
- payload['labels']['alertname'] = title if title
- payload['labels']['gitlab_environment_name'] = environment if environment
-
- payload
- end
-
- # Example: 2018-09-27T18:25:31.079079416Z
- def utc_rfc3339(date)
- date.utc.rfc3339
- rescue
- date
- end
-
- def truncate_to_second(date)
- date.change(usec: 0)
- end
-end
diff --git a/spec/services/projects/prometheus/alerts/create_service_spec.rb b/spec/services/projects/prometheus/alerts/create_service_spec.rb
index 50c776df734..c0bc9336558 100644
--- a/spec/services/projects/prometheus/alerts/create_service_spec.rb
+++ b/spec/services/projects/prometheus/alerts/create_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Prometheus::Alerts::CreateService do
+RSpec.describe Projects::Prometheus::Alerts::CreateService do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
diff --git a/spec/services/projects/prometheus/alerts/destroy_service_spec.rb b/spec/services/projects/prometheus/alerts/destroy_service_spec.rb
index 7205ace8308..573711051b7 100644
--- a/spec/services/projects/prometheus/alerts/destroy_service_spec.rb
+++ b/spec/services/projects/prometheus/alerts/destroy_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Prometheus::Alerts::DestroyService do
+RSpec.describe Projects::Prometheus::Alerts::DestroyService do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:alert) { create(:prometheus_alert, project: project) }
diff --git a/spec/services/projects/prometheus/alerts/notify_service_spec.rb b/spec/services/projects/prometheus/alerts/notify_service_spec.rb
index 95acedb1e76..aae257e3e3a 100644
--- a/spec/services/projects/prometheus/alerts/notify_service_spec.rb
+++ b/spec/services/projects/prometheus/alerts/notify_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Prometheus::Alerts::NotifyService do
+RSpec.describe Projects::Prometheus::Alerts::NotifyService do
include PrometheusHelpers
let_it_be(:project, reload: true) { create(:project) }
@@ -36,48 +36,8 @@ describe Projects::Prometheus::Alerts::NotifyService do
end
end
- shared_examples 'processes incident issues' do |amount|
- let(:create_incident_service) { spy }
-
- it 'processes issues' do
- expect(IncidentManagement::ProcessPrometheusAlertWorker)
- .to receive(:perform_async)
- .with(project.id, kind_of(Hash))
- .exactly(amount).times
-
- Sidekiq::Testing.inline! do
- expect(subject).to be_success
- end
- end
- end
-
- shared_examples 'does not process incident issues' do
- it 'does not process issues' do
- expect(IncidentManagement::ProcessPrometheusAlertWorker)
- .not_to receive(:perform_async)
-
- expect(subject).to be_success
- end
- end
-
- shared_examples 'persists events' do
- let(:create_events_service) { spy }
-
- it 'persists events' do
- expect(Projects::Prometheus::Alerts::CreateEventsService)
- .to receive(:new)
- .and_return(create_events_service)
-
- expect(create_events_service)
- .to receive(:execute)
-
- expect(subject).to be_success
- end
- end
-
shared_examples 'notifies alerts' do
it_behaves_like 'sends notification email'
- it_behaves_like 'persists events'
end
shared_examples 'no notifications' do |http_status:|
@@ -102,6 +62,41 @@ describe Projects::Prometheus::Alerts::NotifyService do
let(:payload_alert_firing) { payload_raw['alerts'].first }
let(:token) { 'token' }
+ context 'with environment specific clusters' do
+ let(:prd_cluster) do
+ cluster
+ end
+
+ let(:stg_cluster) do
+ create(:cluster, :provided_by_user, projects: [project], enabled: true, environment_scope: 'stg/*')
+ end
+
+ let(:stg_environment) do
+ create(:environment, project: project, name: 'stg/1')
+ end
+
+ let(:alert_firing) do
+ create(:prometheus_alert, project: project, environment: stg_environment)
+ end
+
+ before do
+ create(:clusters_applications_prometheus, :installed,
+ cluster: prd_cluster, alert_manager_token: token)
+ create(:clusters_applications_prometheus, :installed,
+ cluster: stg_cluster, alert_manager_token: nil)
+ end
+
+ context 'without token' do
+ let(:token_input) { nil }
+
+ it_behaves_like 'notifies alerts'
+ end
+
+ context 'with token' do
+ it_behaves_like 'no notifications', http_status: :unauthorized
+ end
+ end
+
context 'with project specific cluster' do
using RSpec::Parameterized::TableSyntax
@@ -222,8 +217,6 @@ describe Projects::Prometheus::Alerts::NotifyService do
context 'when incident_management_setting does not exist' do
let!(:setting) { nil }
- it_behaves_like 'persists events'
-
it 'does not send notification email', :sidekiq_might_not_need_inline do
expect_any_instance_of(NotificationService)
.not_to receive(:async)
@@ -241,8 +234,6 @@ describe Projects::Prometheus::Alerts::NotifyService do
create(:project_incident_management_setting, send_email: false, project: project)
end
- it_behaves_like 'persists events'
-
it 'does not send notification' do
expect(NotificationService).not_to receive(:new)
@@ -276,45 +267,6 @@ describe Projects::Prometheus::Alerts::NotifyService do
end
end
end
-
- context 'process incident issues' do
- before do
- create(:prometheus_service, project: project)
- create(:project_alerting_setting, project: project, token: token)
- end
-
- context 'with create_issue setting enabled' do
- before do
- setting.update!(create_issue: true)
- end
-
- it_behaves_like 'processes incident issues', 2
-
- context 'multiple firing alerts' do
- let(:payload_raw) do
- prometheus_alert_payload(firing: [alert_firing, alert_firing], resolved: [])
- end
-
- it_behaves_like 'processes incident issues', 2
- end
-
- context 'without firing alerts' do
- let(:payload_raw) do
- prometheus_alert_payload(firing: [], resolved: [alert_resolved])
- end
-
- it_behaves_like 'processes incident issues', 1
- end
- end
-
- context 'with create_issue setting disabled' do
- before do
- setting.update!(create_issue: false)
- end
-
- it_behaves_like 'does not process incident issues'
- end
- end
end
context 'with invalid payload' do
@@ -345,13 +297,6 @@ describe Projects::Prometheus::Alerts::NotifyService do
subject
end
-
- it 'does not process issues' do
- expect(IncidentManagement::ProcessPrometheusAlertWorker)
- .not_to receive(:perform_async)
-
- subject
- end
end
end
diff --git a/spec/services/projects/prometheus/alerts/update_service_spec.rb b/spec/services/projects/prometheus/alerts/update_service_spec.rb
index 8a99c2679f7..e831d001838 100644
--- a/spec/services/projects/prometheus/alerts/update_service_spec.rb
+++ b/spec/services/projects/prometheus/alerts/update_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Prometheus::Alerts::UpdateService do
+RSpec.describe Projects::Prometheus::Alerts::UpdateService do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:environment) { create(:environment, project: project) }
diff --git a/spec/services/projects/prometheus/metrics/destroy_service_spec.rb b/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
index 81fce82cf46..17cc88b27b6 100644
--- a/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
+++ b/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Prometheus::Metrics::DestroyService do
+RSpec.describe Projects::Prometheus::Metrics::DestroyService do
let(:metric) { create(:prometheus_metric) }
subject { described_class.new(metric) }
diff --git a/spec/services/projects/prometheus/metrics/update_service_spec.rb b/spec/services/projects/prometheus/metrics/update_service_spec.rb
index a53c6ae37cd..bf87093150c 100644
--- a/spec/services/projects/prometheus/metrics/update_service_spec.rb
+++ b/spec/services/projects/prometheus/metrics/update_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::Prometheus::Metrics::UpdateService do
+RSpec.describe Projects::Prometheus::Metrics::UpdateService do
let(:metric) { create(:prometheus_metric) }
it 'updates the prometheus metric' do
diff --git a/spec/services/projects/propagate_service_template_spec.rb b/spec/services/projects/propagate_service_template_spec.rb
index ddc27c037f8..266bf2cc213 100644
--- a/spec/services/projects/propagate_service_template_spec.rb
+++ b/spec/services/projects/propagate_service_template_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::PropagateServiceTemplate do
+RSpec.describe Projects::PropagateServiceTemplate do
describe '.propagate' do
let!(:service_template) do
PushoverService.create(
diff --git a/spec/services/projects/protect_default_branch_service_spec.rb b/spec/services/projects/protect_default_branch_service_spec.rb
index c0b819ab17b..a485a64ca35 100644
--- a/spec/services/projects/protect_default_branch_service_spec.rb
+++ b/spec/services/projects/protect_default_branch_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::ProtectDefaultBranchService do
+RSpec.describe Projects::ProtectDefaultBranchService do
let(:service) { described_class.new(project) }
let(:project) { create(:project) }
diff --git a/spec/services/projects/repository_languages_service_spec.rb b/spec/services/projects/repository_languages_service_spec.rb
index 46c5095327d..cb61a7a1a3e 100644
--- a/spec/services/projects/repository_languages_service_spec.rb
+++ b/spec/services/projects/repository_languages_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::RepositoryLanguagesService do
+RSpec.describe Projects::RepositoryLanguagesService do
let(:service) { described_class.new(project, project.owner) }
context 'when detected_repository_languages flag is set' do
diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb
index 0e2431c0e44..72426a6f6ec 100644
--- a/spec/services/projects/transfer_service_spec.rb
+++ b/spec/services/projects/transfer_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::TransferService do
+RSpec.describe Projects::TransferService do
include GitHelpers
let(:user) { create(:user) }
diff --git a/spec/services/projects/unlink_fork_service_spec.rb b/spec/services/projects/unlink_fork_service_spec.rb
index a6bdc69cdca..6a2c55a5e55 100644
--- a/spec/services/projects/unlink_fork_service_spec.rb
+++ b/spec/services/projects/unlink_fork_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::UnlinkForkService, :use_clean_rails_memory_store_caching do
+RSpec.describe Projects::UnlinkForkService, :use_clean_rails_memory_store_caching do
include ProjectForksHelper
subject { described_class.new(forked_project, user) }
@@ -53,6 +53,7 @@ describe Projects::UnlinkForkService, :use_clean_rails_memory_store_caching do
expect(source.forks_count).to eq(1)
subject.execute
+ BatchLoader::Executor.clear_current
expect(source.forks_count).to be_zero
end
@@ -146,6 +147,7 @@ describe Projects::UnlinkForkService, :use_clean_rails_memory_store_caching do
expect(project.forks_count).to eq(2)
subject.execute
+ BatchLoader::Executor.clear_current
expect(project.forks_count).to be_zero
end
@@ -212,6 +214,7 @@ describe Projects::UnlinkForkService, :use_clean_rails_memory_store_caching do
expect(forked_project.forks_count).to eq(1)
subject.execute
+ BatchLoader::Executor.clear_current
expect(project.forks_count).to eq(1)
expect(forked_project.forks_count).to eq(0)
diff --git a/spec/services/projects/update_pages_configuration_service_spec.rb b/spec/services/projects/update_pages_configuration_service_spec.rb
index 363d3df0f84..c4c9fc779fa 100644
--- a/spec/services/projects/update_pages_configuration_service_spec.rb
+++ b/spec/services/projects/update_pages_configuration_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::UpdatePagesConfigurationService do
+RSpec.describe Projects::UpdatePagesConfigurationService do
let(:project) { create(:project) }
let(:service) { described_class.new(project) }
diff --git a/spec/services/projects/update_pages_service_spec.rb b/spec/services/projects/update_pages_service_spec.rb
index 29c3c300d1b..2e02cb56668 100644
--- a/spec/services/projects/update_pages_service_spec.rb
+++ b/spec/services/projects/update_pages_service_spec.rb
@@ -2,7 +2,7 @@
require "spec_helper"
-describe Projects::UpdatePagesService do
+RSpec.describe Projects::UpdatePagesService do
let_it_be(:project, refind: true) { create(:project, :repository) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) }
let(:build) { create(:ci_build, pipeline: pipeline, ref: 'HEAD') }
diff --git a/spec/services/projects/update_remote_mirror_service_spec.rb b/spec/services/projects/update_remote_mirror_service_spec.rb
index 418973fb0a6..f0a8074f46c 100644
--- a/spec/services/projects/update_remote_mirror_service_spec.rb
+++ b/spec/services/projects/update_remote_mirror_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::UpdateRemoteMirrorService do
+RSpec.describe Projects::UpdateRemoteMirrorService do
let(:project) { create(:project, :repository) }
let(:remote_project) { create(:forked_project_with_submodules) }
let(:remote_mirror) { create(:remote_mirror, project: project, enabled: true) }
diff --git a/spec/services/projects/update_repository_storage_service_spec.rb b/spec/services/projects/update_repository_storage_service_spec.rb
index e37580e7367..57e02c26b71 100644
--- a/spec/services/projects/update_repository_storage_service_spec.rb
+++ b/spec/services/projects/update_repository_storage_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::UpdateRepositoryStorageService do
+RSpec.describe Projects::UpdateRepositoryStorageService do
include Gitlab::ShellAdapter
subject { described_class.new(repository_storage_move) }
@@ -37,14 +37,15 @@ describe Projects::UpdateRepositoryStorageService do
project.repository.path_to_repo
end
- expect(project_repository_double).to receive(:create_repository)
- .and_return(true)
expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw)
expect(project_repository_double).to receive(:checksum)
.and_return(checksum)
+ expect(GitlabShellWorker).to receive(:perform_async).with(:mv_repository, 'default', anything, anything)
+ .and_call_original
result = subject.execute
+ project.reload
expect(result).to be_success
expect(project).not_to be_repository_read_only
@@ -70,8 +71,6 @@ describe Projects::UpdateRepositoryStorageService do
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('default').and_call_original
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('test_second_storage').and_return(SecureRandom.uuid)
- expect(project_repository_double).to receive(:create_repository)
- .and_return(true)
expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw)
.and_raise(Gitlab::Git::CommandError)
@@ -90,8 +89,6 @@ describe Projects::UpdateRepositoryStorageService do
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('default').and_call_original
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('test_second_storage').and_return(SecureRandom.uuid)
- expect(project_repository_double).to receive(:create_repository)
- .and_return(true)
expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw)
expect(project_repository_double).to receive(:checksum)
@@ -113,20 +110,43 @@ describe Projects::UpdateRepositoryStorageService do
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('default').and_call_original
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('test_second_storage').and_return(SecureRandom.uuid)
- expect(project_repository_double).to receive(:create_repository)
- .and_return(true)
expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw)
expect(project_repository_double).to receive(:checksum)
.and_return(checksum)
result = subject.execute
+ project.reload
expect(result).to be_success
expect(project.repository_storage).to eq('test_second_storage')
expect(project.reload_pool_repository).to be_nil
end
end
+
+ context 'when the repository move is finished' do
+ let(:repository_storage_move) { create(:project_repository_storage_move, :finished, project: project, destination_storage_name: destination) }
+
+ it 'is idempotent' do
+ expect do
+ result = subject.execute
+
+ expect(result).to be_success
+ end.not_to change(repository_storage_move, :state)
+ end
+ end
+
+ context 'when the repository move is failed' do
+ let(:repository_storage_move) { create(:project_repository_storage_move, :failed, project: project, destination_storage_name: destination) }
+
+ it 'is idempotent' do
+ expect do
+ result = subject.execute
+
+ expect(result).to be_success
+ end.not_to change(repository_storage_move, :state)
+ end
+ end
end
context 'with wiki repository' do
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index 8a17884f641..6620ee6e697 100644
--- a/spec/services/projects/update_service_spec.rb
+++ b/spec/services/projects/update_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::UpdateService do
+RSpec.describe Projects::UpdateService do
include ExternalAuthorizationServiceHelpers
include ProjectForksHelper
diff --git a/spec/services/projects/update_statistics_service_spec.rb b/spec/services/projects/update_statistics_service_spec.rb
index 8534853fbc7..92e97186be3 100644
--- a/spec/services/projects/update_statistics_service_spec.rb
+++ b/spec/services/projects/update_statistics_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Projects::UpdateStatisticsService do
+RSpec.describe Projects::UpdateStatisticsService do
let(:service) { described_class.new(project, nil, statistics: statistics)}
let(:statistics) { %w(repository_size) }