diff options
Diffstat (limited to 'spec/services')
4 files changed, 39 insertions, 14 deletions
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 fb6d7171ac3..28d8a95fe07 100644 --- a/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb +++ b/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb @@ -1,21 +1,22 @@ require 'spec_helper' describe Projects::HashedStorage::MigrateAttachmentsService do - subject(:service) { described_class.new(project) } + subject(:service) { described_class.new(project, project.full_path, logger: nil) } + let(:project) { create(:project, :legacy_storage) } let(:legacy_storage) { Storage::LegacyProject.new(project) } let(:hashed_storage) { Storage::HashedProject.new(project) } let!(:upload) { Upload.find_by(path: file_uploader.upload_path) } let(:file_uploader) { build(:file_uploader, project: project) } - let(:old_path) { File.join(base_path(legacy_storage), upload.path) } - let(:new_path) { File.join(base_path(hashed_storage), upload.path) } + let(:old_disk_path) { File.join(base_path(legacy_storage), upload.path) } + let(:new_disk_path) { File.join(base_path(hashed_storage), upload.path) } context '#execute' do context 'when succeeds' do it 'moves attachments to hashed storage layout' do - expect(File.file?(old_path)).to be_truthy - expect(File.file?(new_path)).to be_falsey + expect(File.file?(old_disk_path)).to be_truthy + expect(File.file?(new_disk_path)).to be_falsey expect(File.exist?(base_path(legacy_storage))).to be_truthy expect(File.exist?(base_path(hashed_storage))).to be_falsey expect(FileUtils).to receive(:mv).with(base_path(legacy_storage), base_path(hashed_storage)).and_call_original @@ -24,8 +25,8 @@ describe Projects::HashedStorage::MigrateAttachmentsService do expect(File.exist?(base_path(hashed_storage))).to be_truthy expect(File.exist?(base_path(legacy_storage))).to be_falsey - expect(File.file?(old_path)).to be_falsey - expect(File.file?(new_path)).to be_truthy + expect(File.file?(old_disk_path)).to be_falsey + expect(File.file?(new_disk_path)).to be_truthy end end @@ -40,7 +41,7 @@ describe Projects::HashedStorage::MigrateAttachmentsService do service.execute expect(File.exist?(base_path(hashed_storage))).to be_falsey - expect(File.file?(new_path)).to be_falsey + expect(File.file?(new_disk_path)).to be_falsey end end 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 ed4930313c5..5f67c325223 100644 --- a/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb +++ b/spec/services/projects/hashed_storage/migrate_repository_service_spec.rb @@ -3,10 +3,11 @@ require 'spec_helper' describe Projects::HashedStorage::MigrateRepositoryService do let(:gitlab_shell) { Gitlab::Shell.new } let(:project) { create(:project, :legacy_storage, :repository, :wiki_repo) } - let(:service) { described_class.new(project) } let(:legacy_storage) { Storage::LegacyProject.new(project) } let(:hashed_storage) { Storage::HashedProject.new(project) } + subject(:service) { described_class.new(project, project.full_path) } + describe '#execute' do before do allow(service).to receive(:gitlab_shell) { gitlab_shell } diff --git a/spec/services/projects/hashed_storage_migration_service_spec.rb b/spec/services/projects/hashed_storage_migration_service_spec.rb index e8e18bb3ac0..5368c3828dd 100644 --- a/spec/services/projects/hashed_storage_migration_service_spec.rb +++ b/spec/services/projects/hashed_storage_migration_service_spec.rb @@ -2,14 +2,19 @@ require 'spec_helper' describe Projects::HashedStorageMigrationService do let(:project) { create(:project, :empty_repo, :wiki_repo, :legacy_storage) } - subject(:service) { described_class.new(project) } + let(:logger) { double } + + subject(:service) { described_class.new(project, project.full_path, logger: logger) } describe '#execute' do context 'repository migration' do - let(:repository_service) { Projects::HashedStorage::MigrateRepositoryService.new(project, subject.logger) } + let(:repository_service) { Projects::HashedStorage::MigrateRepositoryService.new(project, project.full_path, logger: logger) } it 'delegates migration to Projects::HashedStorage::MigrateRepositoryService' do - expect(Projects::HashedStorage::MigrateRepositoryService).to receive(:new).with(project, subject.logger).and_return(repository_service) + expect(Projects::HashedStorage::MigrateRepositoryService) + .to receive(:new) + .with(project, project.full_path, logger: logger) + .and_return(repository_service) expect(repository_service).to receive(:execute) service.execute @@ -24,10 +29,13 @@ describe Projects::HashedStorageMigrationService do end context 'attachments migration' do - let(:attachments_service) { Projects::HashedStorage::MigrateAttachmentsService.new(project, subject.logger) } + let(:attachments_service) { Projects::HashedStorage::MigrateAttachmentsService.new(project, project.full_path, logger: logger) } it 'delegates migration to Projects::HashedStorage::MigrateRepositoryService' do - expect(Projects::HashedStorage::MigrateAttachmentsService).to receive(:new).with(project, subject.logger).and_return(attachments_service) + expect(Projects::HashedStorage::MigrateAttachmentsService) + .to receive(:new) + .with(project, project.full_path, logger: logger) + .and_return(attachments_service) expect(attachments_service).to receive(:execute) service.execute diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb index e6871545a0b..9572b4110d5 100644 --- a/spec/services/projects/update_service_spec.rb +++ b/spec/services/projects/update_service_spec.rb @@ -248,6 +248,21 @@ describe Projects::UpdateService do expect(project.errors.messages).to have_key(:base) expect(project.errors.messages[:base]).to include('There is already a repository with that name on disk') end + + context 'when hashed storage enabled' do + before do + stub_application_setting(hashed_storage_enabled: true) + end + + it 'migrates project to a hashed storage instead of renaming the repo to another legacy name' do + result = update_project(project, admin, path: 'new-path') + + expect(result).not_to include(status: :error) + expect(project).to be_valid + expect(project.errors).to be_empty + expect(project.reload.hashed_storage?(:repository)).to be_truthy + end + end end context 'with hashed storage' do |