2021-03-08 18:12:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rake_helper'
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
RSpec.describe 'gitlab:pages' do
|
2021-03-08 18:12:59 +05:30
|
|
|
before(:context) do
|
|
|
|
Rake.application.rake_require 'tasks/gitlab/pages'
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe 'migrate_legacy_storage task' do
|
|
|
|
subject { run_rake_task('gitlab:pages:migrate_legacy_storage') }
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'calls migration service' do
|
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
|
|
|
migration_threads: 3,
|
|
|
|
batch_size: 10,
|
|
|
|
ignore_invalid_entries: false) do |service|
|
|
|
|
expect(service).to receive(:execute).and_call_original
|
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
subject
|
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'uses PAGES_MIGRATION_THREADS environment variable' do
|
|
|
|
stub_env('PAGES_MIGRATION_THREADS', '5')
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
|
|
|
migration_threads: 5,
|
|
|
|
batch_size: 10,
|
|
|
|
ignore_invalid_entries: false) do |service|
|
|
|
|
expect(service).to receive(:execute).and_call_original
|
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'uses PAGES_MIGRATION_BATCH_SIZE environment variable' do
|
|
|
|
stub_env('PAGES_MIGRATION_BATCH_SIZE', '100')
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
|
|
|
migration_threads: 3,
|
|
|
|
batch_size: 100,
|
|
|
|
ignore_invalid_entries: false) do |service|
|
|
|
|
expect(service).to receive(:execute).and_call_original
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
subject
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'uses PAGES_MIGRATION_IGNORE_INVALID_ENTRIES environment variable' do
|
|
|
|
stub_env('PAGES_MIGRATION_IGNORE_INVALID_ENTRIES', 'true')
|
|
|
|
|
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
|
|
|
migration_threads: 3,
|
|
|
|
batch_size: 10,
|
|
|
|
ignore_invalid_entries: true) do |service|
|
|
|
|
expect(service).to receive(:execute).and_call_original
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'clean_migrated_zip_storage task' do
|
|
|
|
it 'removes only migrated deployments' do
|
|
|
|
regular_deployment = create(:pages_deployment)
|
|
|
|
migrated_deployment = create(:pages_deployment, :migrated)
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
regular_deployment.project.update_pages_deployment!(regular_deployment)
|
|
|
|
migrated_deployment.project.update_pages_deployment!(migrated_deployment)
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(PagesDeployment.all).to contain_exactly(regular_deployment, migrated_deployment)
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
run_rake_task('gitlab:pages:clean_migrated_zip_storage')
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(PagesDeployment.all).to contain_exactly(regular_deployment)
|
|
|
|
expect(PagesDeployment.find_by_id(regular_deployment.id)).not_to be_nil
|
|
|
|
expect(PagesDeployment.find_by_id(migrated_deployment.id)).to be_nil
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|