diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb')
-rw-r--r-- | spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb b/spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb index e57704d0ebe..3495b535cff 100644 --- a/spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb +++ b/spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb @@ -11,37 +11,53 @@ RSpec.describe 'gitlab:refresh_project_statistics_build_artifacts_size rake task let_it_be(:project_3) { create(:project) } let(:string_of_ids) { "#{project_1.id} #{project_2.id} #{project_3.id} 999999" } + let(:csv_url) { 'https://www.example.com/foo.csv' } + let(:csv_body) do + <<~BODY + PROJECT_ID + #{project_1.id} + #{project_2.id} + #{project_3.id} + BODY + end before do Rake.application.rake_require('tasks/gitlab/refresh_project_statistics_build_artifacts_size') stub_const("BUILD_ARTIFACTS_SIZE_REFRESH_ENQUEUE_BATCH_SIZE", 2) - end - context 'when given a list of space-separated IDs through STDIN' do - before do - allow($stdin).to receive(:tty?).and_return(false) - allow($stdin).to receive(:read).and_return(string_of_ids) - end + stub_request(:get, csv_url).to_return(status: 200, body: csv_body) + allow(Kernel).to receive(:sleep).with(1) + end + context 'when given a list of space-separated IDs through rake argument' do it 'enqueues the projects for refresh' do - expect { run_rake_task(rake_task) }.to output(/Done/).to_stdout + expect { run_rake_task(rake_task, csv_url) }.to output(/Done/).to_stdout expect(Projects::BuildArtifactsSizeRefresh.all.map(&:project)).to match_array([project_1, project_2, project_3]) end - end - context 'when given a list of space-separated IDs through rake argument' do - it 'enqueues the projects for refresh' do - expect { run_rake_task(rake_task, string_of_ids) }.to output(/Done/).to_stdout + it 'inserts refreshes in batches with a sleep' do + expect(Projects::BuildArtifactsSizeRefresh).to receive(:enqueue_refresh).with([project_1, project_2]).ordered + expect(Kernel).to receive(:sleep).with(1) + expect(Projects::BuildArtifactsSizeRefresh).to receive(:enqueue_refresh).with([project_3]).ordered - expect(Projects::BuildArtifactsSizeRefresh.all.map(&:project)).to match_array([project_1, project_2, project_3]) + run_rake_task(rake_task, csv_url) end end - context 'when not given any IDs' do + context 'when CSV has invalid header' do + let(:csv_body) do + <<~BODY + projectid + #{project_1.id} + #{project_2.id} + #{project_3.id} + BODY + end + it 'returns an error message' do - expect { run_rake_task(rake_task) }.to output(/Please provide a string of space-separated project IDs/).to_stdout + expect { run_rake_task(rake_task, csv_url) }.to output(/Project IDs must be listed in the CSV under the header PROJECT_ID/).to_stdout end end end |