Commit 1bfeb700 authored by Kerri Miller's avatar Kerri Miller

Merge branch...

Merge branch 'morefice/ui-should-explain-if-no-junit-report-artifacts-are-available-to-populate-unit-test-report' into 'master'

Render errors if test report artifacts are expired

See merge request gitlab-org/gitlab!83113
parents 6c6f9afd 6d63da22
...@@ -23,12 +23,16 @@ module Projects ...@@ -23,12 +23,16 @@ module Projects
def show def show
respond_to do |format| respond_to do |format|
format.json do format.json do
if Feature.enabled?(:ci_test_report_artifacts_expired, project, default_enabled: :yaml) && pipeline.has_expired_test_reports?
render json: { errors: 'Test report artifacts have expired' }, status: :not_found
else
render json: TestSuiteSerializer render json: TestSuiteSerializer
.new(project: project, current_user: @current_user) .new(project: project, current_user: @current_user)
.represent(test_suite, details: true) .represent(test_suite, details: true)
end end
end end
end end
end
private private
......
...@@ -1285,6 +1285,12 @@ module Ci ...@@ -1285,6 +1285,12 @@ module Ci
end end
end end
def has_expired_test_reports?
strong_memoize(:artifacts_expired) do
!has_reports?(::Ci::JobArtifact.test_reports.not_expired)
end
end
private private
def add_message(severity, content) def add_message(severity, content)
......
---
name: ci_test_report_artifacts_expired
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/83113
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/356773
milestone: '14.10'
type: development
group: group::pipeline insights
default_enabled: false
...@@ -40,6 +40,32 @@ RSpec.describe Projects::Pipelines::TestsController do ...@@ -40,6 +40,32 @@ RSpec.describe Projects::Pipelines::TestsController do
let(:suite_name) { 'test' } let(:suite_name) { 'test' }
let(:build_ids) { pipeline.latest_builds.pluck(:id) } let(:build_ids) { pipeline.latest_builds.pluck(:id) }
context 'when artifacts are expired' do
before do
pipeline.job_artifacts.first.update!(expire_at: Date.yesterday)
end
it 'renders not_found errors', :aggregate_failures do
get_tests_show_json(build_ids)
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['errors']).to eq('Test report artifacts have expired')
end
context 'when ci_test_report_artifacts_expired is disabled' do
before do
stub_feature_flags(ci_test_report_artifacts_expired: false)
end
it 'renders test suite', :aggregate_failures do
get_tests_show_json(build_ids)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['name']).to eq('test')
end
end
end
context 'when artifacts are not expired' do
before do before do
build = main_pipeline.builds.last build = main_pipeline.builds.last
build.update_column(:finished_at, 1.day.ago) # Just to be sure we are included in the report window build.update_column(:finished_at, 1.day.ago) # Just to be sure we are included in the report window
...@@ -49,11 +75,12 @@ RSpec.describe Projects::Pipelines::TestsController do ...@@ -49,11 +75,12 @@ RSpec.describe Projects::Pipelines::TestsController do
Ci::TestFailureHistoryService.new(main_pipeline).execute Ci::TestFailureHistoryService.new(main_pipeline).execute
end end
it 'renders test suite data' do it 'renders test suite data', :aggregate_failures do
get_tests_show_json(build_ids) get_tests_show_json(build_ids)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['name']).to eq('test') expect(json_response['name']).to eq('test')
expect(json_response['artifacts_expired']).to be_falsey
# Each test failure in this pipeline has a matching failure in the default branch # Each test failure in this pipeline has a matching failure in the default branch
recent_failures = json_response['test_cases'].map { |tc| tc['recent_failures'] } recent_failures = json_response['test_cases'].map { |tc| tc['recent_failures'] }
...@@ -64,6 +91,7 @@ RSpec.describe Projects::Pipelines::TestsController do ...@@ -64,6 +91,7 @@ RSpec.describe Projects::Pipelines::TestsController do
]) ])
end end
end end
end
context 'when pipeline has no builds that matches the given build_ids' do context 'when pipeline has no builds that matches the given build_ids' do
let(:pipeline) { create(:ci_empty_pipeline) } let(:pipeline) { create(:ci_empty_pipeline) }
......
...@@ -4713,6 +4713,24 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -4713,6 +4713,24 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end end
end end
describe '#has_expired_test_reports?' do
subject { pipeline_with_test_report.has_expired_test_reports? }
let(:pipeline_with_test_report) { create(:ci_pipeline, :with_test_reports) }
context 'when artifacts are not expired' do
it { is_expected.to be_falsey }
end
context 'when artifacts are expired' do
before do
pipeline_with_test_report.job_artifacts.first.update!(expire_at: Date.yesterday)
end
it { is_expected.to be_truthy }
end
end
it_behaves_like 'it has loose foreign keys' do it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :ci_pipeline } let(:factory_name) { :ci_pipeline }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment