Commit 6be08132 authored by celdem's avatar celdem

Fix nil error when comparing reports

parent da72dc6d
......@@ -9,9 +9,9 @@ module Gitlab
attr_reader :base_report, :head_report
def initialize(base_report = [], head_report = [])
@base_report = base_report
@head_report = head_report
def initialize(base_report, head_report)
@base_report = base_report || []
@head_report = head_report || []
end
def added
......
......@@ -52,12 +52,30 @@ describe Gitlab::Ci::Reports::Security::VulnerabilityReportsComparer do
end
describe 'with empty vulnerabilities' do
let(:comparer) { described_class.new }
it 'returns empty array when reports are not present' do
expect(comparer.existing).to be_empty
expect(comparer.fixed).to be_empty
expect(comparer.added).to be_empty
comparer = described_class.new(nil, nil)
expect(comparer.existing).to eq([])
expect(comparer.fixed).to eq([])
expect(comparer.added).to eq([])
end
it 'returns added vulnerability when base is empty and head is not empty' do
vuln = build(:vulnerabilities_occurrence, report_type: :sast, identifiers: [identifier], location_fingerprint: '888')
comparer = described_class.new(nil, [vuln])
expect(comparer.existing).to eq([])
expect(comparer.fixed).to eq([])
expect(comparer.added).to eq([vuln])
end
it 'returns fixed vulnerability when head is empty and base is not empty' do
vuln = build(:vulnerabilities_occurrence, report_type: :sast, identifiers: [identifier], location_fingerprint: '888')
comparer = described_class.new([vuln], nil)
expect(comparer.existing).to eq([])
expect(comparer.fixed).to eq([vuln])
expect(comparer.added).to eq([])
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