2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
describe Projects::HashedStorage::MigrationService do
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:project) { create(:project, :empty_repo, :wiki_repo, :legacy_storage) }
|
2018-11-18 11:00:15 +05:30
|
|
|
let(:logger) { double }
|
2020-04-22 19:07:51 +05:30
|
|
|
let!(:project_attachment) { build(:file_uploader, project: project) }
|
|
|
|
let(:project_hashed_path) { Storage::Hashed.new(project).disk_path }
|
|
|
|
let(:project_legacy_path) { Storage::LegacyProject.new(project).disk_path }
|
|
|
|
let(:wiki_hashed_path) { "#{project_hashed_path}.wiki" }
|
|
|
|
let(:wiki_legacy_path) { "#{project_legacy_path}.wiki" }
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
subject(:service) { described_class.new(project, project.full_path, logger: logger) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'repository migration' do
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:repository_service) do
|
|
|
|
Projects::HashedStorage::MigrateRepositoryService.new(project: project,
|
|
|
|
old_disk_path: project.full_path,
|
|
|
|
logger: logger)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'delegates migration to Projects::HashedStorage::MigrateRepositoryService' do
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(service).to receive(:migrate_repository_service).and_return(repository_service)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(repository_service).to receive(:execute)
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not delegate migration if repository is already migrated' do
|
|
|
|
project.storage_version = ::Project::LATEST_STORAGE_VERSION
|
|
|
|
expect(Projects::HashedStorage::MigrateRepositoryService).not_to receive(:new)
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
it 'migrates legacy repositories to hashed storage' do
|
|
|
|
legacy_attachments_path = FileUploader.absolute_base_dir(project)
|
|
|
|
hashed_project = project.dup.tap { |p| p.id = project.id }
|
|
|
|
hashed_project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:attachments]
|
|
|
|
hashed_attachments_path = FileUploader.absolute_base_dir(hashed_project)
|
|
|
|
|
|
|
|
expect(logger).to receive(:info).with(/Repository moved from '#{project_legacy_path}' to '#{project_hashed_path}'/)
|
|
|
|
expect(logger).to receive(:info).with(/Repository moved from '#{wiki_legacy_path}' to '#{wiki_hashed_path}'/)
|
|
|
|
expect(logger).to receive(:info).with(/Project attachments moved from '#{legacy_attachments_path}' to '#{hashed_attachments_path}'/)
|
|
|
|
|
|
|
|
expect { service.execute }.to change { project.storage_version }.from(nil).to(2)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'attachments migration' do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:project) { create(:project, :empty_repo, :wiki_repo, storage_version: ::Project::HASHED_STORAGE_FEATURES[:repository]) }
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:attachments_service) do
|
|
|
|
Projects::HashedStorage::MigrateAttachmentsService.new(project: project,
|
|
|
|
old_disk_path: project.full_path,
|
|
|
|
logger: logger)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'delegates migration to Projects::HashedStorage::MigrateRepositoryService' do
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(service).to receive(:migrate_attachments_service).and_return(attachments_service)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(attachments_service).to receive(:execute)
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not delegate migration if attachments are already migrated' do
|
|
|
|
project.storage_version = ::Project::LATEST_STORAGE_VERSION
|
|
|
|
expect(Projects::HashedStorage::MigrateAttachmentsService).not_to receive(:new)
|
|
|
|
|
|
|
|
service.execute
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
it 'migrates legacy attachments to hashed storage' do
|
|
|
|
legacy_attachments_path = FileUploader.absolute_base_dir(project)
|
|
|
|
hashed_project = project.dup.tap { |p| p.id = project.id }
|
|
|
|
hashed_project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:attachments]
|
|
|
|
hashed_attachments_path = FileUploader.absolute_base_dir(hashed_project)
|
|
|
|
|
|
|
|
expect(logger).to receive(:info).with(/Project attachments moved from '#{legacy_attachments_path}' to '#{hashed_attachments_path}'/)
|
|
|
|
|
|
|
|
expect { service.execute }.to change { project.storage_version }.from(1).to(2)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|