From 16f41a5b04934bb7a7a26ac2d6516cb44b7932e3 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 3 Nov 2021 21:10:35 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/scripts/pipeline_test_report_builder_spec.rb | 174 ++++++++++++++-------- 1 file changed, 111 insertions(+), 63 deletions(-) (limited to 'spec/scripts/pipeline_test_report_builder_spec.rb') diff --git a/spec/scripts/pipeline_test_report_builder_spec.rb b/spec/scripts/pipeline_test_report_builder_spec.rb index 8a5388f4db8..8553ada044e 100644 --- a/spec/scripts/pipeline_test_report_builder_spec.rb +++ b/spec/scripts/pipeline_test_report_builder_spec.rb @@ -9,30 +9,39 @@ RSpec.describe PipelineTestReportBuilder do subject do described_class.new( - project: 'gitlab-org/gitlab', + target_project: 'gitlab-org/gitlab', mr_id: '999', instance_base_url: 'https://gitlab.com', output_file_path: output_file_path ) end - let(:mr_pipelines) do - [ - { - 'status' => 'running', - 'created_at' => DateTime.now.to_s - }, - { - 'status' => 'failed', - 'created_at' => (DateTime.now - 5).to_s - } - ] + let(:failed_pipeline_url) { 'pipeline2_url' } + + let(:failed_pipeline) do + { + 'status' => 'failed', + 'created_at' => (DateTime.now - 5).to_s, + 'web_url' => failed_pipeline_url + } end + let(:current_pipeline) do + { + 'status' => 'running', + 'created_at' => DateTime.now.to_s, + 'web_url' => 'pipeline1_url' + } + end + + let(:mr_pipelines) { [current_pipeline, failed_pipeline] } + + let(:failed_build_id) { 9999 } + let(:failed_builds_for_pipeline) do [ { - 'id' => 9999, + 'id' => failed_build_id, 'stage' => 'test' } ] @@ -62,75 +71,114 @@ RSpec.describe PipelineTestReportBuilder do before do allow(subject).to receive(:pipelines_for_mr).and_return(mr_pipelines) allow(subject).to receive(:failed_builds_for_pipeline).and_return(failed_builds_for_pipeline) - allow(subject).to receive(:test_report_for_build).and_return(test_report_for_build) end - describe '#test_report_for_latest_pipeline' do - context 'no previous pipeline' do - let(:mr_pipelines) { [] } + describe '#previous_pipeline' do + let(:fork_pipeline_url) { 'fork_pipeline_url' } + let(:fork_pipeline) do + { + 'status' => 'failed', + 'created_at' => (DateTime.now - 5).to_s, + 'web_url' => fork_pipeline_url + } + end - it 'returns empty hash' do - expect(subject.test_report_for_latest_pipeline).to eq("{}") - end + before do + allow(subject).to receive(:test_report_for_build).and_return(test_report_for_build) end - context 'first pipeline scenario' do - let(:mr_pipelines) do - [ - { - 'status' => 'running', - 'created_at' => DateTime.now.to_s - } - ] + context 'pipeline in a fork project' do + let(:mr_pipelines) { [current_pipeline, fork_pipeline] } + + it 'returns fork pipeline' do + expect(subject.previous_pipeline).to eq(fork_pipeline) end + end - it 'returns empty hash' do - expect(subject.test_report_for_latest_pipeline).to eq("{}") + context 'pipeline in target project' do + it 'returns failed pipeline' do + expect(subject.previous_pipeline).to eq(failed_pipeline) end end + end - context 'no previous failed pipeline' do - let(:mr_pipelines) do - [ - { - 'status' => 'running', - 'created_at' => DateTime.now.to_s - }, - { - 'status' => 'success', - 'created_at' => (DateTime.now - 5).to_s - } - ] + describe '#test_report_for_latest_pipeline' do + 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 + end + + context 'canonical pipeline' do + before do + allow(subject).to receive(:test_report_for_build).and_return(test_report_for_build) end - it 'returns empty hash' do - expect(subject.test_report_for_latest_pipeline).to eq("{}") + context 'no previous pipeline' do + let(:mr_pipelines) { [] } + + it 'returns empty hash' do + expect(subject.test_report_for_latest_pipeline).to eq("{}") + end end - end - context 'no failed test builds' do - let(:failed_builds_for_pipeline) do - [ - { - 'id' => 9999, - 'stage' => 'prepare' - } - ] + context 'first pipeline scenario' do + let(:mr_pipelines) do + [ + { + 'status' => 'running', + 'created_at' => DateTime.now.to_s + } + ] + end + + it 'returns empty hash' do + expect(subject.test_report_for_latest_pipeline).to eq("{}") + end end - it 'returns empty hash' do - expect(subject.test_report_for_latest_pipeline).to eq("{}") + context 'no previous failed pipeline' do + let(:mr_pipelines) do + [ + { + 'status' => 'running', + 'created_at' => DateTime.now.to_s + }, + { + 'status' => 'success', + 'created_at' => (DateTime.now - 5).to_s + } + ] + end + + it 'returns empty hash' do + expect(subject.test_report_for_latest_pipeline).to eq("{}") + end + end + + context 'no failed test builds' do + let(:failed_builds_for_pipeline) do + [ + { + 'id' => 9999, + 'stage' => 'prepare' + } + ] + end + + it 'returns empty hash' do + expect(subject.test_report_for_latest_pipeline).to eq("{}") + end end - end - context 'failed pipeline and failed test builds' do - it 'returns populated test list for suites' do - actual = subject.test_report_for_latest_pipeline - expected = { - 'suites' => [test_report_for_build] - }.to_json + context 'failed pipeline and failed test builds' do + it 'returns populated test list for suites' do + actual = subject.test_report_for_latest_pipeline + expected = { + 'suites' => [test_report_for_build] + }.to_json - expect(actual).to eq(expected) + expect(actual).to eq(expected) + end end end end -- cgit v1.2.3