2020-12-23 01:10:22 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rake_helper'
|
|
|
|
|
2021-06-08 11:10:00 -04:00
|
|
|
RSpec.describe 'gitlab:pages', :silence_stdout do
|
2020-12-23 01:10:22 -05:00
|
|
|
before(:context) do
|
|
|
|
Rake.application.rake_require 'tasks/gitlab/pages'
|
|
|
|
end
|
|
|
|
|
2021-02-10 07:09:45 -05:00
|
|
|
describe 'migrate_legacy_storage task' do
|
|
|
|
subject { run_rake_task('gitlab:pages:migrate_legacy_storage') }
|
2020-12-23 01:10:22 -05:00
|
|
|
|
2021-02-10 07:09:45 -05:00
|
|
|
it 'calls migration service' do
|
2021-02-11 16:09:00 -05:00
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
2021-04-05 17:09:19 -04:00
|
|
|
ignore_invalid_entries: false,
|
|
|
|
mark_projects_as_not_deployed: false) do |service|
|
2021-04-15 11:09:11 -04:00
|
|
|
expect(service).to receive(:execute_with_threads).with(threads: 3, batch_size: 10).and_call_original
|
2021-02-10 07:09:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
2021-01-22 13:09:10 -05:00
|
|
|
end
|
2020-12-23 01:10:22 -05:00
|
|
|
|
2021-02-10 07:09:45 -05:00
|
|
|
it 'uses PAGES_MIGRATION_THREADS environment variable' do
|
|
|
|
stub_env('PAGES_MIGRATION_THREADS', '5')
|
2020-12-23 01:10:22 -05:00
|
|
|
|
2021-02-11 16:09:00 -05:00
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
2021-04-05 17:09:19 -04:00
|
|
|
ignore_invalid_entries: false,
|
|
|
|
mark_projects_as_not_deployed: false) do |service|
|
2021-04-15 11:09:11 -04:00
|
|
|
expect(service).to receive(:execute_with_threads).with(threads: 5, batch_size: 10).and_call_original
|
2021-02-10 07:09:45 -05:00
|
|
|
end
|
2020-12-23 01:10:22 -05:00
|
|
|
|
2021-02-10 07:09:45 -05:00
|
|
|
subject
|
2020-12-23 01:10:22 -05:00
|
|
|
end
|
|
|
|
|
2021-02-10 07:09:45 -05:00
|
|
|
it 'uses PAGES_MIGRATION_BATCH_SIZE environment variable' do
|
|
|
|
stub_env('PAGES_MIGRATION_BATCH_SIZE', '100')
|
2020-12-23 01:10:22 -05:00
|
|
|
|
2021-02-11 16:09:00 -05:00
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
2021-04-05 17:09:19 -04:00
|
|
|
ignore_invalid_entries: false,
|
|
|
|
mark_projects_as_not_deployed: false) do |service|
|
2021-04-15 11:09:11 -04:00
|
|
|
expect(service).to receive(:execute_with_threads).with(threads: 3, batch_size: 100).and_call_original
|
2021-02-11 16:09:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
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,
|
2021-04-05 17:09:19 -04:00
|
|
|
ignore_invalid_entries: true,
|
|
|
|
mark_projects_as_not_deployed: false) do |service|
|
2021-04-15 11:09:11 -04:00
|
|
|
expect(service).to receive(:execute_with_threads).with(threads: 3, batch_size: 10).and_call_original
|
2021-04-05 17:09:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses PAGES_MIGRATION_MARK_PROJECTS_AS_NOT_DEPLOYED environment variable' do
|
|
|
|
stub_env('PAGES_MIGRATION_MARK_PROJECTS_AS_NOT_DEPLOYED', 'true')
|
|
|
|
|
|
|
|
expect_next_instance_of(::Pages::MigrateFromLegacyStorageService, anything,
|
|
|
|
ignore_invalid_entries: false,
|
|
|
|
mark_projects_as_not_deployed: true) do |service|
|
2021-04-15 11:09:11 -04:00
|
|
|
expect(service).to receive(:execute_with_threads).with(threads: 3, batch_size: 10).and_call_original
|
2021-02-10 07:09:45 -05:00
|
|
|
end
|
2020-12-23 01:10:22 -05:00
|
|
|
|
2021-02-10 07:09:45 -05:00
|
|
|
subject
|
2020-12-23 01:10:22 -05:00
|
|
|
end
|
2021-02-10 07:09:45 -05:00
|
|
|
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-01-22 13:09:10 -05:00
|
|
|
|
2021-02-10 07:09:45 -05:00
|
|
|
regular_deployment.project.update_pages_deployment!(regular_deployment)
|
|
|
|
migrated_deployment.project.update_pages_deployment!(migrated_deployment)
|
|
|
|
|
|
|
|
expect(PagesDeployment.all).to contain_exactly(regular_deployment, migrated_deployment)
|
|
|
|
|
|
|
|
run_rake_task('gitlab:pages:clean_migrated_zip_storage')
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
2020-12-23 01:10:22 -05:00
|
|
|
end
|
2021-04-15 11:09:11 -04:00
|
|
|
|
|
|
|
describe 'gitlab:pages:deployments:migrate_to_object_storage' do
|
|
|
|
subject { run_rake_task('gitlab:pages:deployments:migrate_to_object_storage') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_pages_object_storage(::Pages::DeploymentUploader, enabled: object_storage_enabled)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:deployment) { create(:pages_deployment, file_store: store) }
|
|
|
|
let(:object_storage_enabled) { true }
|
|
|
|
|
|
|
|
context 'when local storage is used' do
|
|
|
|
let(:store) { ObjectStorage::Store::LOCAL }
|
|
|
|
|
|
|
|
context 'and remote storage is defined' do
|
|
|
|
it 'migrates file to remote storage' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(deployment.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and remote storage is not defined' do
|
|
|
|
let(:object_storage_enabled) { false }
|
|
|
|
|
|
|
|
it 'fails to migrate to remote storage' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(deployment.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when remote storage is used' do
|
|
|
|
let(:store) { ObjectStorage::Store::REMOTE }
|
|
|
|
|
|
|
|
it 'file stays on remote storage' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(deployment.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'gitlab:pages:deployments:migrate_to_local' do
|
|
|
|
subject { run_rake_task('gitlab:pages:deployments:migrate_to_local') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_pages_object_storage(::Pages::DeploymentUploader, enabled: object_storage_enabled)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:deployment) { create(:pages_deployment, file_store: store) }
|
|
|
|
let(:object_storage_enabled) { true }
|
|
|
|
|
|
|
|
context 'when remote storage is used' do
|
|
|
|
let(:store) { ObjectStorage::Store::REMOTE }
|
|
|
|
|
|
|
|
context 'and job has remote file store defined' do
|
|
|
|
it 'migrates file to local storage' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(deployment.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when local storage is used' do
|
|
|
|
let(:store) { ObjectStorage::Store::LOCAL }
|
|
|
|
|
|
|
|
it 'file stays on local storage' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(deployment.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-12-23 01:10:22 -05:00
|
|
|
end
|