diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-06 15:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-06 15:08:36 +0300 |
commit | c1f785fe21ee785618ef3bf0407fee166b6e0ecd (patch) | |
tree | 4807aa3c9dfa10ac1e52554057e407b1af310888 /spec/scripts | |
parent | 5d3eac1cf8820b5f95bf2085ccc246ea78f4b4d2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/scripts')
-rw-r--r-- | spec/scripts/pipeline_test_report_builder_spec.rb | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/spec/scripts/pipeline_test_report_builder_spec.rb b/spec/scripts/pipeline_test_report_builder_spec.rb index 8553ada044e..198cdefc530 100644 --- a/spec/scripts/pipeline_test_report_builder_spec.rb +++ b/spec/scripts/pipeline_test_report_builder_spec.rb @@ -103,16 +103,18 @@ RSpec.describe PipelineTestReportBuilder do end describe '#test_report_for_latest_pipeline' do + let(:failed_build_uri) { "#{failed_pipeline_url}/tests/suite.json?build_ids[]=#{failed_build_id}" } + + before do + allow(subject).to receive(:fetch).with(failed_build_uri).and_return(failed_builds_for_pipeline) + end + it 'fetches builds from pipeline related to MR' do - expect(subject).to receive(:fetch).with("#{failed_pipeline_url}/tests/suite.json?build_ids[]=#{failed_build_id}").and_return(failed_builds_for_pipeline) - subject.test_report_for_latest_pipeline + expected = { "suites" => [failed_builds_for_pipeline] }.to_json + expect(subject.test_report_for_latest_pipeline).to eq(expected) end context 'canonical pipeline' do - before do - allow(subject).to receive(:test_report_for_build).and_return(test_report_for_build) - end - context 'no previous pipeline' do let(:mr_pipelines) { [] } @@ -171,6 +173,10 @@ RSpec.describe PipelineTestReportBuilder do end context 'failed pipeline and failed test builds' do + before do + allow(subject).to receive(:fetch).with(failed_build_uri).and_return(test_report_for_build) + end + it 'returns populated test list for suites' do actual = subject.test_report_for_latest_pipeline expected = { @@ -180,6 +186,36 @@ RSpec.describe PipelineTestReportBuilder do expect(actual).to eq(expected) end end + + context 'when receiving a server error' do + let(:response) { instance_double('Net::HTTPResponse') } + let(:error) { Net::HTTPServerException.new('server error', response) } + let(:test_report_for_latest_pipeline) { subject.test_report_for_latest_pipeline } + + before do + allow(response).to receive(:code).and_return(response_code) + allow(subject).to receive(:fetch).with(failed_build_uri).and_raise(error) + end + + context 'when response code is 404' do + let(:response_code) { 404 } + + it 'continues without the missing reports' do + expected = { 'suites' => [] }.to_json + + expect { test_report_for_latest_pipeline }.not_to raise_error + expect(test_report_for_latest_pipeline).to eq(expected) + end + end + + context 'when response code is unexpected' do + let(:response_code) { 500 } + + it 'raises HTTPServerException' do + expect { test_report_for_latest_pipeline }.to raise_error(error) + end + end + end end end end |