Commit 24e0354b authored by mo khan's avatar mo khan Committed by James Fargher

Check if HEAD report is nil

parent 7e096de7
---
title: Check if HEAD report is nil when diffing license_scanning reports
merge_request: 43210
author:
type: fixed
...@@ -169,14 +169,15 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do ...@@ -169,14 +169,15 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do
end end
describe '#diff_with' do describe '#diff_with' do
subject { base_report.diff_with(head_report) }
def names_from(licenses) def names_from(licenses)
licenses.map(&:name) licenses.map(&:name)
end end
context 'when the other report is not available' do context 'when the other report is not available' do
subject { base_report.diff_with(nil) }
let(:base_report) { build(:license_scan_report, :version_2) } let(:base_report) { build(:license_scan_report, :version_2) }
let(:head_report) { nil }
before do before do
base_report base_report
...@@ -184,17 +185,17 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do ...@@ -184,17 +185,17 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do
.add_dependency('rails') .add_dependency('rails')
end end
specify { expect(names_from(subject[:removed])).to contain_exactly('MIT License') } specify do
specify { expect(subject[:added]).to be_empty } expect(names_from(subject[:removed])).to contain_exactly('MIT License')
specify { expect(subject[:unchanged]).to be_empty } expect(subject[:added]).to be_empty
expect(subject[:unchanged]).to be_empty
end
end end
context 'when diffing two v1 reports' do context 'when diffing two v1 reports' do
let(:base_report) { build(:license_scan_report, :version_1) } let(:base_report) { build(:license_scan_report, :version_1) }
let(:head_report) { build(:license_scan_report, :version_1) } let(:head_report) { build(:license_scan_report, :version_1) }
subject { base_report.diff_with(head_report) }
before do before do
base_report.add_license(id: nil, name: 'MIT').add_dependency('Library1') base_report.add_license(id: nil, name: 'MIT').add_dependency('Library1')
base_report.add_license(id: nil, name: 'BSD').add_dependency('Library1') base_report.add_license(id: nil, name: 'BSD').add_dependency('Library1')
...@@ -214,8 +215,6 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do ...@@ -214,8 +215,6 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do
let(:base_report) { build(:license_scan_report, :version_2) } let(:base_report) { build(:license_scan_report, :version_2) }
let(:head_report) { build(:license_scan_report, :version_2) } let(:head_report) { build(:license_scan_report, :version_2) }
subject { base_report.diff_with(head_report) }
before do before do
base_report.add_license(id: 'MIT', name: 'MIT').add_dependency('Library1') base_report.add_license(id: 'MIT', name: 'MIT').add_dependency('Library1')
base_report.add_license(id: 'BSD-3-Clause', name: 'BSD').add_dependency('Library1') base_report.add_license(id: 'BSD-3-Clause', name: 'BSD').add_dependency('Library1')
...@@ -235,8 +234,6 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do ...@@ -235,8 +234,6 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do
let(:base_report) { build(:license_scan_report, :version_1) } let(:base_report) { build(:license_scan_report, :version_1) }
let(:head_report) { build(:license_scan_report, :version_2) } let(:head_report) { build(:license_scan_report, :version_2) }
subject { base_report.diff_with(head_report) }
before do before do
base_report.add_license(id: nil, name: 'MIT').add_dependency('Library1') base_report.add_license(id: nil, name: 'MIT').add_dependency('Library1')
base_report.add_license(id: nil, name: 'BSD').add_dependency('Library1') base_report.add_license(id: nil, name: 'BSD').add_dependency('Library1')
...@@ -256,8 +253,6 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do ...@@ -256,8 +253,6 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Report do
let(:base_report) { build(:license_scan_report, :version_2) } let(:base_report) { build(:license_scan_report, :version_2) }
let(:head_report) { build(:license_scan_report, :version_1) } let(:head_report) { build(:license_scan_report, :version_1) }
subject { base_report.diff_with(head_report) }
before do before do
base_report.add_license(id: 'MIT', name: 'MIT').add_dependency('Library1') base_report.add_license(id: 'MIT', name: 'MIT').add_dependency('Library1')
base_report.add_license(id: 'BSD-3-Clause', name: 'BSD').add_dependency('Library1') base_report.add_license(id: 'BSD-3-Clause', name: 'BSD').add_dependency('Library1')
......
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