Commit c13fdd44 authored by Maxime Orefice's avatar Maxime Orefice

Strip out junit screenshot path

This commit moves our business logic to strip out the build group
project path from our capybara configuration to our junit parser.

Changelog: changed
parent 38235936
......@@ -994,7 +994,7 @@ module Ci
end
def latest_test_report_builds
latest_report_builds(Ci::JobArtifact.test_reports).preload(:project)
latest_report_builds(Ci::JobArtifact.test_reports).preload(:project, :job_variables, :metadata)
end
def builds_with_coverage
......
......@@ -66,6 +66,7 @@ module Gitlab
status = ::Gitlab::Ci::Reports::TestCase::STATUS_FAILED
system_output = data['failure']
attachment = attachment_path(data['system_out'])
attachment = remove_project_prefix(attachment, job)
elsif data.key?('error')
status = ::Gitlab::Ci::Reports::TestCase::STATUS_ERROR
system_output = data['error']
......@@ -100,6 +101,10 @@ module Gitlab
matches = data.match(ATTACHMENT_TAG_REGEX)
matches[:path] if matches
end
def remove_project_prefix(attachment, job)
attachment&.delete_prefix(job.variables['CI_PROJECT_DIR']&.value || '')
end
end
end
end
......
......@@ -8,8 +8,14 @@ RSpec.describe Gitlab::Ci::Parsers::Test::Junit do
let(:test_suite) { Gitlab::Ci::Reports::TestSuite.new('rspec') }
let(:test_cases) { flattened_test_cases(test_suite) }
let(:job) { double(max_test_cases_per_report: max_test_cases) }
let(:variables) { [{ key: 'CI_PROJECT_DIR', value: '/builds/group/project' }] }
let(:max_test_cases) { 0 }
let(:job) do
double(
max_test_cases_per_report: max_test_cases,
variables: Gitlab::Ci::Variables::Collection.new.concat(variables)
)
end
context 'when data is JUnit style XML' do
context 'when there are no <testcases> in <testsuite>' do
......@@ -417,6 +423,27 @@ RSpec.describe Gitlab::Ci::Parsers::Test::Junit do
end
end
context 'when paths contains the build group project path' do
let(:junit) do
<<~EOF
<testsuites>
<testsuite>
<testcase classname='Calculator' name='sumTest1' time='0.01'>
<failure>Some failure</failure>
<system-out>[[ATTACHMENT|/builds/group/project/some/path.png]]</system-out>
</testcase>
</testsuite>
</testsuites>
EOF
end
it 'removes the builds group project path prefix' do
expect { subject }.not_to raise_error
expect(test_cases[0].attachment).to eq("/some/path.png")
end
end
private
def flattened_test_cases(test_suite)
......
......@@ -177,7 +177,6 @@ RSpec.configure do |config|
config.append_after do |example|
if example.metadata[:screenshot]
screenshot = example.metadata[:screenshot][:image] || example.metadata[:screenshot][:html]
screenshot&.delete_prefix!(ENV.fetch('CI_PROJECT_DIR', ''))
example.metadata[:stdout] = %{[[ATTACHMENT|#{screenshot}]]}
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