Commit e7fe1ea6 authored by Maxime Orefice's avatar Maxime Orefice Committed by Shinya Maeda

Add filtering ability for JUnit

Filter a TestReport by attachment
Filter a TestSuite by attachment
parent 1ac0b06d
......@@ -34,6 +34,14 @@ module Gitlab
end
end
def with_attachment!
@test_suites.keep_if do |_job_name, test_suite|
test_suite.with_attachment!.present?
end
self
end
TestCase::STATUS_TYPES.each do |status_type|
define_method("#{status_type}_count") do
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -37,6 +37,16 @@ module Gitlab
end
end
def with_attachment!
@test_cases = @test_cases.extract!("failed")
@test_cases.keep_if do |status, hash|
hash.any? do |key, test_case|
test_case.has_attachment?
end
end
end
TestCase::STATUS_TYPES.each do |status_type|
define_method("#{status_type}") do
test_cases[status_type] || {}
......
......@@ -11,7 +11,12 @@ FactoryBot.define do
attachment { nil }
association :job, factory: :ci_build
trait :failed do
status { "failed" }
end
trait :with_attachment do
status { "failed" }
attachment { "some/path.png" }
end
......
......@@ -109,6 +109,38 @@ describe Gitlab::Ci::Reports::TestReports do
end
end
describe '#with_attachment' do
let(:test_case) { build(:test_case, :failed) }
subject { test_reports.with_attachment! }
context 'when test suites do not contain an attachment' do
before do
test_reports.get_suite('rspec').add_test_case(create_test_case_rspec_success)
test_reports.get_suite('junit').add_test_case(test_case)
end
it 'returns empty test suites' do
expect(subject.test_suites).to be_empty
end
end
context 'when test suites contain an attachment' do
let(:test_case_succes) { build(:test_case) }
let(:test_case_with_attachment) { build(:test_case, :with_attachment) }
before do
test_reports.get_suite('rspec').add_test_case(test_case_succes)
test_reports.get_suite('junit').add_test_case(test_case_with_attachment)
end
it 'returns test suites with attachment' do
expect(subject.test_suites.count).to eq(1)
expect(subject.test_suites['junit'].test_cases['failed']).to be_present
end
end
end
Gitlab::Ci::Reports::TestCase::STATUS_TYPES.each do |status_type|
describe "##{status_type}_count" do
subject { test_reports.public_send("#{status_type}_count") }
......
......@@ -85,6 +85,35 @@ describe Gitlab::Ci::Reports::TestSuite do
end
end
describe '#with_attachment' do
subject { test_suite.with_attachment! }
context 'when test cases do not contain an attachment' do
let(:test_case) { build(:test_case, :failed)}
before do
test_suite.add_test_case(test_case)
end
it 'returns an empty hash' do
expect(subject).to be_empty
end
end
context 'when test cases contain an attachment' do
let(:test_case_with_attachment) { build(:test_case, :with_attachment)}
before do
test_suite.add_test_case(test_case_with_attachment)
end
it 'returns failed test cases with attachment' do
expect(subject.count).to eq(1)
expect(subject['failed']).to be_present
end
end
end
Gitlab::Ci::Reports::TestCase::STATUS_TYPES.each do |status_type|
describe "##{status_type}" do
subject { test_suite.public_send("#{status_type}") }
......
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