diff options
author | Fabio Pitino <fpitino@gitlab.com> | 2019-05-03 10:29:11 +0100 |
---|---|---|
committer | Fabio Pitino <fpitino@gitlab.com> | 2019-05-17 08:28:36 +0100 |
commit | 0f10e88a256ee803884967b4e34a866e156aea5c (patch) | |
tree | 2f64d59ae3c75c57f349d6b00acf923406d10fec | |
parent | a73ee1cc3cc78f1f25034be9394e980ff5209ecc (diff) | |
download | gitlab-ce-0f10e88a256ee803884967b4e34a866e156aea5c.tar.gz |
If classname attribute is not present in JUnit testcase, default to file
Partially fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/50964
-rw-r--r-- | lib/gitlab/ci/reports/test_case.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/parsers/test/junit_spec.rb | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/gitlab/ci/reports/test_case.rb b/lib/gitlab/ci/reports/test_case.rb index 292e273a03a..3e061a9b672 100644 --- a/lib/gitlab/ci/reports/test_case.rb +++ b/lib/gitlab/ci/reports/test_case.rb @@ -14,7 +14,7 @@ module Gitlab def initialize(name:, classname:, execution_time:, status:, file: nil, system_output: nil, stack_trace: nil) @name = name - @classname = classname + @classname = classname.present? ? classname : file @file = file @execution_time = execution_time.to_f @status = status diff --git a/spec/lib/gitlab/ci/parsers/test/junit_spec.rb b/spec/lib/gitlab/ci/parsers/test/junit_spec.rb index a49402c7398..e1ab3b2e367 100644 --- a/spec/lib/gitlab/ci/parsers/test/junit_spec.rb +++ b/spec/lib/gitlab/ci/parsers/test/junit_spec.rb @@ -116,6 +116,30 @@ describe Gitlab::Ci::Parsers::Test::Junit do end end + context 'when there are two test cases without classname' do + let(:junit) do + <<-EOF.strip_heredoc + <testsuite> + <testcase name='sumTest1' time='0.01' file='./path/to/file1'></testcase> + <testcase name='sumTest2' time='0.02' file='./path/to/file2'></testcase> + </testsuite> + EOF + end + + it 'parses XML and adds test cases to a suite defaulting classname to file attribute' do + expect { subject }.not_to raise_error + + expect(test_cases[0].classname).to eq('./path/to/file1') + expect(test_cases[0].file).to eq('./path/to/file1') + expect(test_cases[0].name).to eq('sumTest1') + expect(test_cases[0].execution_time).to eq(0.01) + expect(test_cases[1].classname).to eq('./path/to/file2') + expect(test_cases[1].file).to eq('./path/to/file2') + expect(test_cases[1].name).to eq('sumTest2') + expect(test_cases[1].execution_time).to eq(0.02) + end + end + context 'when there are two test suites' do let(:junit) do <<-EOF.strip_heredoc |