Commit 9e99436d authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'zj-fix-coverage-bug' into 'master'

Return nil as coverage instead of a File object

See merge request !10633
parents ebb358e9 23fbbe0c
...@@ -3,7 +3,6 @@ class BuildCoverageWorker ...@@ -3,7 +3,6 @@ class BuildCoverageWorker
include BuildQueue include BuildQueue
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id) Ci::Build.find_by(id: build_id)&.update_coverage
.try(:update_coverage)
end end
end end
...@@ -76,11 +76,14 @@ module Gitlab ...@@ -76,11 +76,14 @@ module Gitlab
stream.each_line do |line| stream.each_line do |line|
matches = line.scan(regex) matches = line.scan(regex)
next unless matches.is_a?(Array) next unless matches.is_a?(Array)
next if matches.empty?
match = matches.flatten.last match = matches.flatten.last
coverage = match.gsub(/\d+(\.\d+)?/).first coverage = match.gsub(/\d+(\.\d+)?/).first
return coverage.to_f if coverage.present? return coverage if coverage.present?
end end
nil
rescue rescue
# if bad regex or something goes wrong we dont want to interrupt transition # if bad regex or something goes wrong we dont want to interrupt transition
# so we just silentrly ignore error for now # so we just silentrly ignore error for now
......
...@@ -167,7 +167,7 @@ describe Gitlab::Ci::Trace::Stream do ...@@ -167,7 +167,7 @@ describe Gitlab::Ci::Trace::Stream do
let(:data) { 'Coverage 1033 / 1051 LOC (98.29%) covered' } let(:data) { 'Coverage 1033 / 1051 LOC (98.29%) covered' }
let(:regex) { '\(\d+.\d+\%\) covered' } let(:regex) { '\(\d+.\d+\%\) covered' }
it { is_expected.to eq(98.29) } it { is_expected.to eq("98.29") }
end end
context 'valid content & bad regex' do context 'valid content & bad regex' do
...@@ -188,14 +188,14 @@ describe Gitlab::Ci::Trace::Stream do ...@@ -188,14 +188,14 @@ describe Gitlab::Ci::Trace::Stream do
let(:data) { ' (98.39%) covered. (98.29%) covered' } let(:data) { ' (98.39%) covered. (98.29%) covered' }
let(:regex) { '\(\d+.\d+\%\) covered' } let(:regex) { '\(\d+.\d+\%\) covered' }
it { is_expected.to eq(98.29) } it { is_expected.to eq("98.29") }
end end
context 'using a regex capture' do context 'using a regex capture' do
let(:data) { 'TOTAL 9926 3489 65%' } let(:data) { 'TOTAL 9926 3489 65%' }
let(:regex) { 'TOTAL\s+\d+\s+\d+\s+(\d{1,3}\%)' } let(:regex) { 'TOTAL\s+\d+\s+\d+\s+(\d{1,3}\%)' }
it { is_expected.to eq(65) } it { is_expected.to eq("65") }
end end
end end
end end
...@@ -40,12 +40,24 @@ describe Gitlab::Ci::Trace do ...@@ -40,12 +40,24 @@ describe Gitlab::Ci::Trace do
describe '#extract_coverage' do describe '#extract_coverage' do
let(:regex) { '\(\d+.\d+\%\) covered' } let(:regex) { '\(\d+.\d+\%\) covered' }
before do context 'matching coverage' do
trace.set('Coverage 1033 / 1051 LOC (98.29%) covered') before do
trace.set('Coverage 1033 / 1051 LOC (98.29%) covered')
end
it "returns valid coverage" do
expect(trace.extract_coverage(regex)).to eq("98.29")
end
end end
it "returns valid coverage" do context 'no coverage' do
expect(trace.extract_coverage(regex)).to eq(98.29) before do
trace.set('No coverage')
end
it 'returs nil' do
expect(trace.extract_coverage(regex)).to be_nil
end
end end
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