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
path: root/spec
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2018-08-03 17:34:28 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-08-03 17:34:28 +0300
commit10df0eb7cb57a6aefcb869e64e33a1a9a204e349 (patch)
tree05be6e9fa7cfc709ac063e0bcce067030190473b /spec
parent7ae5879bdda17a5dd9d0e02fb47371bfc8270c71 (diff)
Resolve "Hashed storage: extend "Enable hashed storage for all new projects" to "for all new and renamed projects""
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_spec.rb19
-rw-r--r--spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb17
-rw-r--r--spec/services/projects/hashed_storage/migrate_repository_service_spec.rb3
-rw-r--r--spec/services/projects/hashed_storage_migration_service_spec.rb18
-rw-r--r--spec/services/projects/update_service_spec.rb15
-rw-r--r--spec/workers/project_migrate_hashed_storage_worker_spec.rb2
6 files changed, 57 insertions, 17 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 340d2d95500..4313d52d60a 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -3107,6 +3107,19 @@ describe Project do
allow(project).to receive(:previous_changes).and_return('path' => ['foo'])
end
+ context 'migration to hashed storage' do
+ it 'calls HashedStorageMigrationService with correct options' do
+ project = create(:project, :repository, :legacy_storage)
+ allow(project).to receive(:previous_changes).and_return('path' => ['foo'])
+
+ expect_next_instance_of(::Projects::HashedStorageMigrationService) do |service|
+ expect(service).to receive(:execute).and_return(true)
+ end
+
+ project.rename_repo
+ end
+ end
+
it 'renames a repository' do
stub_container_registry_config(enabled: false)
@@ -3153,8 +3166,10 @@ describe Project do
context 'when not rolled out' do
let(:project) { create(:project, :repository, storage_version: 1, skip_disk_validation: true) }
- it 'moves pages folder to new location' do
- expect_any_instance_of(Gitlab::UploadsTransfer).to receive(:rename_project)
+ it 'moves pages folder to hashed storage' do
+ expect_next_instance_of(Projects::HashedStorage::MigrateAttachmentsService) do |service|
+ expect(service).to receive(:execute)
+ end
project.rename_repo
end
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
diff --git a/spec/workers/project_migrate_hashed_storage_worker_spec.rb b/spec/workers/project_migrate_hashed_storage_worker_spec.rb
index 9551e358af1..3703320418b 100644
--- a/spec/workers/project_migrate_hashed_storage_worker_spec.rb
+++ b/spec/workers/project_migrate_hashed_storage_worker_spec.rb
@@ -28,7 +28,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do
migration_service = spy
allow(::Projects::HashedStorageMigrationService)
- .to receive(:new).with(project, subject.logger)
+ .to receive(:new).with(project, project.full_path, logger: subject.logger)
.and_return(migration_service)
subject.perform(project.id)