diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/tasks/gitlab/uploads/migrate_rake_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/tasks/gitlab/uploads/migrate_rake_spec.rb')
-rw-r--r-- | spec/tasks/gitlab/uploads/migrate_rake_spec.rb | 150 |
1 files changed, 55 insertions, 95 deletions
diff --git a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb index e293271ca67..3a368a5011b 100644 --- a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb @@ -2,133 +2,93 @@ require 'rake_helper' -RSpec.describe 'gitlab:uploads:migrate and migrate_to_local rake tasks', :silence_stdout do - let(:model_class) { nil } - let(:uploader_class) { nil } - let(:mounted_as) { nil } - let(:batch_size) { 3 } - +RSpec.describe 'gitlab:uploads:migrate and migrate_to_local rake tasks', :sidekiq_inline, :silence_stdout do before do - stub_env('MIGRATION_BATCH_SIZE', batch_size.to_s) - stub_uploads_object_storage(uploader_class) + stub_env('MIGRATION_BATCH_SIZE', 3.to_s) + stub_uploads_object_storage(AvatarUploader) + stub_uploads_object_storage(FileUploader) Rake.application.rake_require 'tasks/gitlab/uploads/migrate' - allow(ObjectStorage::MigrateUploadsWorker).to receive(:perform_async) + 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 end - context "for AvatarUploader" do - let(:uploader_class) { AvatarUploader } - let(:mounted_as) { :avatar } + let(:total_uploads_count) { 6 } - context "for Project" do - let(:model_class) { Project } - let!(:projects) { create_list(:project, 10, :with_avatar) } + it 'migrates all uploads to object storage in batches' do + expect(ObjectStorage::MigrateUploadsWorker) + .to receive(:perform_async).twice.and_call_original - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 - end + run_rake_task('gitlab:uploads:migrate:all') - context "for Group" do - let(:model_class) { Group } + expect(Upload.with_files_stored_locally.count).to eq(0) + expect(Upload.with_files_stored_remotely.count).to eq(total_uploads_count) + end - before do - create_list(:group, 10, :with_avatar) - end + 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) - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 - end + expect(ObjectStorage::MigrateUploadsWorker) + .to receive(:perform_async).twice.and_call_original - context "for User" do - let(:model_class) { User } + run_rake_task('gitlab:uploads:migrate_to_local:all') - before do - create_list(:user, 10, :with_avatar) - end - - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 - end + expect(Upload.with_files_stored_remotely.count).to eq(0) + expect(Upload.with_files_stored_locally.count).to eq(total_uploads_count) end - context "for AttachmentUploader" do - let(:uploader_class) { AttachmentUploader } + shared_examples 'migrate task with filters' do + it 'migrates matching uploads to object storage' do + run_rake_task('gitlab:uploads:migrate', task_arguments) - context "for Note" do - let(:model_class) { Note } - let(:mounted_as) { :attachment } + migrated_count = matching_uploads.with_files_stored_remotely.count - before do - create_list(:note, 10, :with_attachment) - end - - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 + expect(migrated_count).to eq(matching_uploads.count) + expect(Upload.with_files_stored_locally.count).to eq(total_uploads_count - migrated_count) end - context "for Appearance" do - let(:model_class) { Appearance } - let(:mounted_as) { :logo } + 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) - before do - create(:appearance, :with_logos) - end + migrated_count = matching_uploads.with_files_stored_locally.count - %i(logo header_logo).each do |mount| - it_behaves_like 'enqueue upload migration jobs in batch', batch: 1 do - let(:mounted_as) { mount } - end - end + expect(migrated_count).to eq(matching_uploads.count) + expect(Upload.with_files_stored_remotely.count).to eq(total_uploads_count - migrated_count) end end - context "for FileUploader" do - let(:uploader_class) { FileUploader } - let(:model_class) { Project } + context 'when uploader_class is given' do + let(:task_arguments) { ['FileUploader'] } + let(:matching_uploads) { Upload.where(uploader: 'FileUploader') } - before do - create_list(:project, 10) do |model| - uploader_class.new(model) - .store!(fixture_file_upload('spec/fixtures/doc_sample.txt')) - end - end - - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 + it_behaves_like 'migrate task with filters' end - context "for PersonalFileUploader" do - let(:uploader_class) { PersonalFileUploader } - let(:model_class) { PersonalSnippet } - - before do - create_list(:personal_snippet, 10) do |model| - uploader_class.new(model) - .store!(fixture_file_upload('spec/fixtures/doc_sample.txt')) - end - end + context 'when model_class is given' do + let(:task_arguments) { [nil, 'Project'] } + let(:matching_uploads) { Upload.where(model_type: 'Project') } - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 + it_behaves_like 'migrate task with filters' end - context "for NamespaceFileUploader" do - let(:uploader_class) { NamespaceFileUploader } - let(:model_class) { Snippet } + context 'when mounted_as is given' do + let(:task_arguments) { [nil, nil, :avatar] } + let(:matching_uploads) { Upload.where(mount_point: :avatar) } - before do - create_list(:snippet, 10) do |model| - uploader_class.new(model) - .store!(fixture_file_upload('spec/fixtures/doc_sample.txt')) - end - end - - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 + it_behaves_like 'migrate task with filters' end - context 'for DesignManagement::DesignV432x230Uploader' do - let(:uploader_class) { DesignManagement::DesignV432x230Uploader } - let(:model_class) { DesignManagement::Action } - let(:mounted_as) { :image_v432x230 } - - before do - create_list(:design_action, 10, :with_image_v432x230) - end + context 'when multiple filters are given' do + let(:task_arguments) { %w[AvatarUploader Project] } + let(:matching_uploads) { Upload.where(uploader: 'AvatarUploader', model_type: 'Project') } - it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 + it_behaves_like 'migrate task with filters' end end |