diff options
Diffstat (limited to 'spec/services/projects')
-rw-r--r-- | spec/services/projects/hashed_storage/migrate_repository_service_spec.rb | 36 | ||||
-rw-r--r-- | spec/services/projects/hashed_storage/rollback_repository_service_spec.rb | 36 |
2 files changed, 72 insertions, 0 deletions
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 e03e75653ff..f0fd243f0ca 100644 --- a/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb +++ b/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb @@ -77,6 +77,42 @@ RSpec.describe Projects::HashedStorage::MigrateRepositoryService do end end + context 'when exception happens' do + it 'handles OpenSSL::Cipher::CipherError' do + expect(project).to receive(:ensure_runners_token).and_raise(OpenSSL::Cipher::CipherError) + + expect { service.execute }.not_to raise_exception + end + + it 'ensures rollback when OpenSSL::Cipher::CipherError' do + expect(project).to receive(:ensure_runners_token).and_raise(OpenSSL::Cipher::CipherError) + expect(service).to receive(:rollback_folder_move).and_call_original + + service.execute + project.reload + + expect(project.legacy_storage?).to be_truthy + expect(project.repository_read_only?).to be_falsey + end + + it 'handles Gitlab::Git::CommandError' do + expect(project).to receive(:write_repository_config).and_raise(Gitlab::Git::CommandError) + + expect { service.execute }.not_to raise_exception + end + + it 'ensures rollback when Gitlab::Git::CommandError' do + expect(project).to receive(:write_repository_config).and_raise(Gitlab::Git::CommandError) + expect(service).to receive(:rollback_folder_move).and_call_original + + service.execute + project.reload + + expect(project.legacy_storage?).to be_truthy + expect(project.repository_read_only?).to be_falsey + end + end + context 'when one move fails' do it 'rollsback repositories to original name' do allow(service).to receive(:move_repository).and_call_original 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 f2b1ce30a54..492eb0956aa 100644 --- a/spec/services/projects/hashed_storage/rollback_repository_service_spec.rb +++ b/spec/services/projects/hashed_storage/rollback_repository_service_spec.rb @@ -77,6 +77,42 @@ RSpec.describe Projects::HashedStorage::RollbackRepositoryService, :clean_gitlab end end + context 'when exception happens' do + it 'handles OpenSSL::Cipher::CipherError' do + expect(project).to receive(:ensure_runners_token).and_raise(OpenSSL::Cipher::CipherError) + + expect { service.execute }.not_to raise_exception + end + + it 'ensures rollback when OpenSSL::Cipher::CipherError' do + expect(project).to receive(:ensure_runners_token).and_raise(OpenSSL::Cipher::CipherError) + expect(service).to receive(:rollback_folder_move).and_call_original + + service.execute + project.reload + + expect(project.hashed_storage?(:repository)).to be_truthy + expect(project.repository_read_only?).to be_falsey + end + + it 'handles Gitlab::Git::CommandError' do + expect(project).to receive(:write_repository_config).and_raise(Gitlab::Git::CommandError) + + expect { service.execute }.not_to raise_exception + end + + it 'ensures rollback when Gitlab::Git::CommandError' do + expect(project).to receive(:write_repository_config).and_raise(Gitlab::Git::CommandError) + expect(service).to receive(:rollback_folder_move).and_call_original + + service.execute + project.reload + + expect(project.hashed_storage?(:repository)).to be_truthy + expect(project.repository_read_only?).to be_falsey + end + end + context 'when one move fails' do it 'rolls repositories back to original name' do allow(service).to receive(:move_repository).and_call_original |