debian-mirror-gitlab/spec/tasks/gitlab/uploads/migrate_rake_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
3.2 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
require 'rake_helper'
2022-10-11 01:57:18 +05:30
RSpec.describe 'gitlab:uploads:migrate and migrate_to_local rake tasks', :sidekiq_inline, :silence_stdout do
2018-05-09 12:01:36 +05:30
before do
2022-10-11 01:57:18 +05:30
stub_env('MIGRATION_BATCH_SIZE', 3.to_s)
stub_uploads_object_storage(AvatarUploader)
stub_uploads_object_storage(FileUploader)
2018-05-09 12:01:36 +05:30
Rake.application.rake_require 'tasks/gitlab/uploads/migrate'
2022-10-11 01:57:18 +05:30
create_list(:project, 2, :with_avatar)
create_list(:group, 2, :with_avatar)
create_list(:project, 2) do |model|
FileUploader.new(model).store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
end
2018-05-09 12:01:36 +05:30
end
2022-10-11 01:57:18 +05:30
let(:total_uploads_count) { 6 }
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
it 'migrates all uploads to object storage in batches' do
expect(ObjectStorage::MigrateUploadsWorker)
.to receive(:perform_async).twice.and_call_original
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
run_rake_task('gitlab:uploads:migrate:all')
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
expect(Upload.with_files_stored_locally.count).to eq(0)
expect(Upload.with_files_stored_remotely.count).to eq(total_uploads_count)
end
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
it 'migrates all uploads to local storage in batches' do
run_rake_task('gitlab:uploads:migrate')
expect(Upload.with_files_stored_remotely.count).to eq(total_uploads_count)
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
expect(ObjectStorage::MigrateUploadsWorker)
.to receive(:perform_async).twice.and_call_original
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
run_rake_task('gitlab:uploads:migrate_to_local:all')
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
expect(Upload.with_files_stored_remotely.count).to eq(0)
expect(Upload.with_files_stored_locally.count).to eq(total_uploads_count)
2018-05-09 12:01:36 +05:30
end
2022-10-11 01:57:18 +05:30
shared_examples 'migrate task with filters' do
it 'migrates matching uploads to object storage' do
run_rake_task('gitlab:uploads:migrate', task_arguments)
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
migrated_count = matching_uploads.with_files_stored_remotely.count
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
expect(migrated_count).to eq(matching_uploads.count)
expect(Upload.with_files_stored_locally.count).to eq(total_uploads_count - migrated_count)
2018-05-09 12:01:36 +05:30
end
2022-10-11 01:57:18 +05:30
it 'migrates matching uploads to local storage' do
run_rake_task('gitlab:uploads:migrate')
expect(Upload.with_files_stored_remotely.count).to eq(total_uploads_count)
run_rake_task('gitlab:uploads:migrate_to_local', task_arguments)
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
migrated_count = matching_uploads.with_files_stored_locally.count
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
expect(migrated_count).to eq(matching_uploads.count)
expect(Upload.with_files_stored_remotely.count).to eq(total_uploads_count - migrated_count)
2018-05-09 12:01:36 +05:30
end
end
2022-10-11 01:57:18 +05:30
context 'when uploader_class is given' do
let(:task_arguments) { ['FileUploader'] }
let(:matching_uploads) { Upload.where(uploader: 'FileUploader') }
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'migrate task with filters'
2018-05-09 12:01:36 +05:30
end
2022-10-11 01:57:18 +05:30
context 'when model_class is given' do
let(:task_arguments) { [nil, 'Project'] }
let(:matching_uploads) { Upload.where(model_type: 'Project') }
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'migrate task with filters'
2018-05-09 12:01:36 +05:30
end
2022-10-11 01:57:18 +05:30
context 'when mounted_as is given' do
let(:task_arguments) { [nil, nil, :avatar] }
let(:matching_uploads) { Upload.where(mount_point: :avatar) }
2018-05-09 12:01:36 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'migrate task with filters'
2018-05-09 12:01:36 +05:30
end
2020-05-24 23:13:21 +05:30
2022-10-11 01:57:18 +05:30
context 'when multiple filters are given' do
let(:task_arguments) { %w[AvatarUploader Project] }
let(:matching_uploads) { Upload.where(uploader: 'AvatarUploader', model_type: 'Project') }
2020-05-24 23:13:21 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'migrate task with filters'
2020-05-24 23:13:21 +05:30
end
2018-05-09 12:01:36 +05:30
end