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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/projects/after_rename_service_spec.rb')
-rw-r--r--spec/services/projects/after_rename_service_spec.rb56
1 files changed, 53 insertions, 3 deletions
diff --git a/spec/services/projects/after_rename_service_spec.rb b/spec/services/projects/after_rename_service_spec.rb
index 4b2569f6b2d..228dff6aa0b 100644
--- a/spec/services/projects/after_rename_service_spec.rb
+++ b/spec/services/projects/after_rename_service_spec.rb
@@ -26,6 +26,7 @@ RSpec.describe Projects::AfterRenameService, feature_category: :groups_and_proje
let(:hash) { Digest::SHA2.hexdigest(project.id.to_s) }
let(:hashed_prefix) { File.join('@hashed', hash[0..1], hash[2..3]) }
let(:hashed_path) { File.join(hashed_prefix, hash) }
+ let(:message) { "Repository #{full_path_before_rename} could not be renamed to #{full_path_after_rename}" }
before do
# Project#gitlab_shell returns a new instance of Gitlab::Shell on every
@@ -35,6 +36,15 @@ RSpec.describe Projects::AfterRenameService, feature_category: :groups_and_proje
stub_application_setting(hashed_storage_enabled: true)
end
+ shared_examples 'logging and raising a RenameFailedError' do
+ it 'logs raises a RenameFailedError' do
+ expect_any_instance_of(described_class).to receive(:log_error).with(message)
+
+ expect { service_execute }
+ .to raise_error(described_class::RenameFailedError)
+ end
+ end
+
it 'renames a repository' do
stub_container_registry_config(enabled: false)
@@ -47,8 +57,21 @@ RSpec.describe Projects::AfterRenameService, feature_category: :groups_and_proje
service_execute
end
+ context 'when renaming or migrating fails' do
+ before do
+ allow_any_instance_of(::Projects::HashedStorage::MigrationService)
+ .to receive(:execute).and_return(false)
+ end
+
+ it_behaves_like 'logging and raising a RenameFailedError'
+ end
+
context 'container registry with images' do
let(:container_repository) { create(:container_repository) }
+ let(:message) do
+ "Project #{full_path_before_rename} cannot be renamed because images are " \
+ "present in its container registry"
+ end
before do
stub_container_registry_config(enabled: true)
@@ -56,9 +79,36 @@ RSpec.describe Projects::AfterRenameService, feature_category: :groups_and_proje
project.container_repositories << container_repository
end
- it 'raises a RenameFailedError' do
- expect { service_execute }
- .to raise_error(described_class::RenameFailedError)
+ context 'when Gitlab API is not supported' do
+ before do
+ allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(false)
+ end
+
+ it_behaves_like 'logging and raising a RenameFailedError'
+ end
+
+ context 'when Gitlab API Client is supported' do
+ before do
+ allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(true)
+ end
+
+ it 'renames the base repository in the registry' do
+ expect(ContainerRegistry::GitlabApiClient).to receive(:rename_base_repository_path)
+ .with(full_path_before_rename, name: path_after_rename).and_return(:ok)
+
+ service_execute
+ end
+
+ context 'when the base repository rename in the registry fails' do
+ before do
+ allow(ContainerRegistry::GitlabApiClient)
+ .to receive(:rename_base_repository_path).and_return(:bad_request)
+ end
+
+ let(:message) { 'Renaming the base repository in the registry failed with error bad_request.' }
+
+ it_behaves_like 'logging and raising a RenameFailedError'
+ end
end
end