summaryrefslogtreecommitdiff
path: root/spec/tasks/gitlab/refresh_project_statistics_build_artifacts_size_rake_spec.rb
diff options
context:
space:
mode:
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.rb44
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