BigW Consortium Gitlab

storage_rake_spec.rb 1.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
require 'rake_helper'

describe 'gitlab:storage rake tasks' do
  before do
    Rake.application.rake_require 'tasks/gitlab/storage'

    stub_warn_user_is_not_gitlab
  end

  describe 'migrate_to_hashed rake task' do
    context '0 legacy projects' do
      it 'does nothing' do
        expect(StorageMigratorWorker).not_to receive(:perform_async)

        run_rake_task('gitlab:storage:migrate_to_hashed')
      end
    end

    context '5 legacy projects' do
      let(:projects) { create_list(:project, 5, storage_version: 0) }

      context 'in batches of 1' do
        before do
          stub_env('BATCH' => 1)
        end

        it 'enqueues one StorageMigratorWorker per project' do
          projects.each do |project|
            expect(StorageMigratorWorker).to receive(:perform_async).with(project.id, project.id)
          end

          run_rake_task('gitlab:storage:migrate_to_hashed')
        end
      end

      context 'in batches of 2' do
        before do
          stub_env('BATCH' => 2)
        end

        it 'enqueues one StorageMigratorWorker per 2 projects' do
          projects.map(&:id).sort.each_slice(2) do |first, last|
            last ||= first
            expect(StorageMigratorWorker).to receive(:perform_async).with(first, last)
          end

          run_rake_task('gitlab:storage:migrate_to_hashed')
        end
      end
    end
  end
end