diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/tasks | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/tasks')
-rw-r--r-- | spec/tasks/gitlab/artifacts/migrate_rake_spec.rb | 12 | ||||
-rw-r--r-- | spec/tasks/gitlab/gitaly_rake_spec.rb | 10 | ||||
-rw-r--r-- | spec/tasks/gitlab/snippets_rake_spec.rb | 114 | ||||
-rw-r--r-- | spec/tasks/gitlab/task_helpers_spec.rb | 15 | ||||
-rw-r--r-- | spec/tasks/gitlab/uploads/migrate_rake_spec.rb | 12 | ||||
-rw-r--r-- | spec/tasks/gitlab/workhorse_rake_spec.rb | 2 |
6 files changed, 145 insertions, 20 deletions
diff --git a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb index 55bfb7acd9d..9ee00b4297b 100644 --- a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb @@ -22,18 +22,6 @@ describe 'gitlab:artifacts namespace rake task' do context 'when local storage is used' do let(:store) { ObjectStorage::Store::LOCAL } - context 'and job does not have file store defined' do - let(:object_storage_enabled) { true } - let(:store) { nil } - - it "migrates file to remote storage" do - subject - - expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE) - expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE) - end - end - context 'and remote storage is defined' do let(:object_storage_enabled) { true } diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb index 0cc92680582..d9fdc183bfe 100644 --- a/spec/tasks/gitlab/gitaly_rake_spec.rb +++ b/spec/tasks/gitlab/gitaly_rake_spec.rb @@ -46,15 +46,13 @@ describe 'gitlab:gitaly namespace rake task' do it 'calls checkout_or_clone_version with the right arguments' do expect(main_object) - .to receive(:checkout_or_clone_version).with(version: version, repo: repo, target_dir: clone_path) + .to receive(:checkout_or_clone_version).with(version: version, repo: repo, target_dir: clone_path, clone_opts: %w[--depth 1]) subject end end describe 'gmake/make' do - let(:command_preamble) { %w[/usr/bin/env -u RUBYOPT -u BUNDLE_GEMFILE] } - before do stub_env('CI', false) FileUtils.mkdir_p(clone_path) @@ -69,7 +67,7 @@ describe 'gitlab:gitaly namespace rake task' do it 'calls gmake in the gitaly directory' do expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0]) - expect(main_object).to receive(:run_command!).with(command_preamble + %w[gmake]).and_return(true) + expect(Gitlab::Popen).to receive(:popen).with(%w[gmake], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil }).and_return(true) subject end @@ -82,7 +80,7 @@ describe 'gitlab:gitaly namespace rake task' do end it 'calls make in the gitaly directory' do - expect(main_object).to receive(:run_command!).with(command_preamble + %w[make]).and_return(true) + expect(Gitlab::Popen).to receive(:popen).with(%w[make], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil }).and_return(true) subject end @@ -99,7 +97,7 @@ describe 'gitlab:gitaly namespace rake task' do end it 'calls make in the gitaly directory with --no-deployment flag for bundle' do - expect(main_object).to receive(:run_command!).with(command_preamble + command).and_return(true) + expect(Gitlab::Popen).to receive(:popen).with(command, nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil }).and_return(true) subject end diff --git a/spec/tasks/gitlab/snippets_rake_spec.rb b/spec/tasks/gitlab/snippets_rake_spec.rb new file mode 100644 index 00000000000..c4bb8d7897c --- /dev/null +++ b/spec/tasks/gitlab/snippets_rake_spec.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +require 'rake_helper' + +describe 'gitlab:snippets namespace rake task' do + let_it_be(:user) { create(:user)} + let_it_be(:migrated) { create(:personal_snippet, :repository, author: user) } + let(:non_migrated) { create_list(:personal_snippet, 3, author: user) } + let(:non_migrated_ids) { non_migrated.pluck(:id) } + + before :all do + Rake.application.rake_require 'tasks/gitlab/snippets' + end + + describe 'migrate' do + subject { run_rake_task('gitlab:snippets:migrate') } + + before do + stub_env('SNIPPET_IDS' => non_migrated_ids.join(',')) + end + + it 'can migrate specific snippets passing ids' do + expect_next_instance_of(Gitlab::BackgroundMigration::BackfillSnippetRepositories) do |instance| + expect(instance).to receive(:perform_by_ids).with(non_migrated_ids).and_call_original + end + + expect { subject }.to output(/All snippets were migrated successfully/).to_stdout + end + + it 'returns the ids of those snippet that failed the migration' do + expect_next_instance_of(Gitlab::BackgroundMigration::BackfillSnippetRepositories) do |instance| + expect(instance).to receive(:perform_by_ids).with(non_migrated_ids) + end + + expect { subject }.to output(/The following snippets couldn't be migrated:\n#{non_migrated_ids.join(',')}/).to_stdout + end + + it 'fails if the SNIPPET_IDS env var is not set' do + stub_env('SNIPPET_IDS' => nil) + + expect { subject }.to raise_error(RuntimeError, 'Please supply the list of ids through the SNIPPET_IDS env var') + end + + it 'fails if the number of ids provided is higher than the limit' do + stub_env('LIMIT' => 2) + + expect { subject }.to raise_error(RuntimeError, /The number of ids provided is higher than/) + end + + it 'fails if the env var LIMIT is invalid' do + stub_env('LIMIT' => 'foo') + + expect { subject }.to raise_error(RuntimeError, 'Invalid limit value') + end + + it 'fails if the ids are invalid' do + stub_env('SNIPPET_IDS' => '1,2,a') + + expect { subject }.to raise_error(RuntimeError, 'Invalid id provided') + end + + it 'fails if the snippet background migration is running' do + Sidekiq::Testing.disable! do + BackgroundMigrationWorker.perform_in(180, 'BackfillSnippetRepositories', [non_migrated.first.id, non_migrated.last.id]) + expect(Sidekiq::ScheduledSet.new).to be_one + + expect { subject }.to raise_error(RuntimeError, /There are already snippet migrations running/) + + Sidekiq::ScheduledSet.new.clear + end + end + end + + describe 'migration_status' do + subject { run_rake_task('gitlab:snippets:migration_status') } + + it 'returns a message when the background migration is not running' do + expect { subject }.to output("There are no snippet migrations running\n").to_stdout + end + + it 'returns a message saying that the background migration is running' do + Sidekiq::Testing.disable! do + BackgroundMigrationWorker.perform_in(180, 'BackfillSnippetRepositories', [non_migrated.first.id, non_migrated.last.id]) + expect(Sidekiq::ScheduledSet.new).to be_one + + expect { subject }.to output("There are snippet migrations running\n").to_stdout + + Sidekiq::ScheduledSet.new.clear + end + end + end + + describe 'list_non_migrated' do + subject { run_rake_task('gitlab:snippets:list_non_migrated') } + + it 'returns a message if all snippets are migrated' do + expect { subject }.to output("All snippets have been successfully migrated\n").to_stdout + end + + context 'when there are still non migrated snippets' do + let!(:non_migrated) { create_list(:personal_snippet, 3, author: user) } + + it 'returns a message returning the non migrated snippets ids' do + expect { subject }.to output(/#{non_migrated_ids}/).to_stdout + end + + it 'returns as many snippet ids as the limit set' do + stub_env('LIMIT' => 1) + + expect { subject }.to output(/#{non_migrated_ids[0]}/).to_stdout + end + end + end +end diff --git a/spec/tasks/gitlab/task_helpers_spec.rb b/spec/tasks/gitlab/task_helpers_spec.rb index 4546d3bdfaf..8e6872f4d6f 100644 --- a/spec/tasks/gitlab/task_helpers_spec.rb +++ b/spec/tasks/gitlab/task_helpers_spec.rb @@ -28,7 +28,7 @@ describe Gitlab::TaskHelpers do context "target_dir doesn't exist" do it 'clones the repo' do - expect(subject).to receive(:clone_repo).with(repo, clone_path) + expect(subject).to receive(:clone_repo).with(repo, clone_path, clone_opts: []) subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path) end @@ -45,6 +45,12 @@ describe Gitlab::TaskHelpers do subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path) end end + + it 'accepts clone_opts' do + expect(subject).to receive(:clone_repo).with(repo, clone_path, clone_opts: %w[--depth 1]) + + subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path, clone_opts: %w[--depth 1]) + end end describe '#clone_repo' do @@ -54,6 +60,13 @@ describe Gitlab::TaskHelpers do subject.clone_repo(repo, clone_path) end + + it 'accepts clone_opts' do + expect(subject) + .to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} clone --depth 1 -- #{repo} #{clone_path}]) + + subject.clone_repo(repo, clone_path, clone_opts: %w[--depth 1]) + end end describe '#checkout_version' do diff --git a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb index 8ea0a98a1dc..49026cd74f9 100644 --- a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb @@ -119,4 +119,16 @@ describe 'gitlab:uploads:migrate and migrate_to_local rake tasks' do it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 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 + + it_behaves_like 'enqueue upload migration jobs in batch', batch: 4 + end end diff --git a/spec/tasks/gitlab/workhorse_rake_spec.rb b/spec/tasks/gitlab/workhorse_rake_spec.rb index b7877a84185..139652ac258 100644 --- a/spec/tasks/gitlab/workhorse_rake_spec.rb +++ b/spec/tasks/gitlab/workhorse_rake_spec.rb @@ -36,7 +36,7 @@ describe 'gitlab:workhorse namespace rake task' do it 'calls checkout_or_clone_version with the right arguments' do expect(main_object) - .to receive(:checkout_or_clone_version).with(version: version, repo: repo, target_dir: clone_path) + .to receive(:checkout_or_clone_version).with(version: version, repo: repo, target_dir: clone_path, clone_opts: %w[--depth 1]) run_rake_task('gitlab:workhorse:install', clone_path) end |