Commit c2faf5ba authored by Micaël Bergeron's avatar Micaël Bergeron

add the specs

parent b3139aa7
require 'gitlab/utils/bisect_enumerable.rb'
require_relative 'helpers.rb'
require_relative 'helpers'
include UploadTaskHelpers
module UploadTask
module Migrate
......@@ -102,14 +103,14 @@ namespace :gitlab do
uploader_class,
model_class,
mounted_as,
ObjectStorage::Store::LOCAL
ObjectStorage::Store::REMOTE
)
migrator.migrate(batch_size) do |results|
UploadTask::Migrate::Reporter.new(results).report
end
puts "\n === Migration summary ==="
puts "\n=== Migration summary ==="
migrator.report
end
end
......
......@@ -24,4 +24,61 @@ describe 'gitlab:uploads rake tasks' do
expect { run_rake_task('gitlab:uploads:check') }.to output(/File checksum \(9e697aa09fe196909813ee36103e34f721fe47a5fdc8aac0e4e4ac47b9b38282\) does not match the one in the database \(#{upload.checksum}\)/).to_stdout
end
end
describe 'migrate' do
let!(:projects) { create_list(:project, 10, :with_avatar) }
let(:model_class) { Project }
let(:uploader_class) { AvatarUploader }
let(:mounted_as) { :avatar }
let(:batch_size) { 3 }
before do
ENV['BATCH'] = batch_size.to_s
stub_uploads_object_storage(uploader_class)
Rake.application.rake_require 'tasks/gitlab/uploads/migrate'
end
def run
args = [uploader_class.to_s, model_class.to_s, mounted_as].compact
run_rake_task("gitlab:uploads:migrate", *args)
end
shared_examples 'outputs correctly' do |success: 0, failures: 0|
total = success + failures
it 'outputs the results for each batch' do
batch_count = [batch_size, total].min
expect { run }.to output(%r{Migrated #{batch_count}/#{batch_count} files}).to_stdout
end if success > 0
it 'outputs the results for the task' do
expect { run }.to output(%r{Migrated #{success}/#{total} files}).to_stdout
end if success > 0
it 'outputs upload failures' do
expect { run }.to output(/Error .* I am a teapot/).to_stdout
end if failures > 0
end
it_behaves_like 'outputs correctly', success: 10
it 'migrates files' do
run
aggregate_failures do
projects.each do |project|
expect(project.reload.avatar.upload.local?).to be_falsey
end
end
end
context 'migration is unsuccessful' do
before do
allow_any_instance_of(ObjectStorage::Concern).to receive(:migrate!).and_raise(CarrierWave::UploadError, "I am a teapot.")
end
it_behaves_like 'outputs correctly', failures: 10
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment