summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/reports/sbom/report_spec.rb
blob: f9a83378f464162bdba80beba711a6ad64d70997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Reports::Sbom::Report do
  subject(:report) { described_class.new }

  describe '#valid?' do
    context 'when there are no errors' do
      it { is_expected.to be_valid }
    end

    context 'when report contains errors' do
      before do
        report.add_error('error1')
        report.add_error('error2')
      end

      it { is_expected.not_to be_valid }
    end
  end

  describe '#add_error' do
    it 'appends errors to a list' do
      report.add_error('error1')
      report.add_error('error2')

      expect(report.errors).to match_array(%w[error1 error2])
    end
  end

  describe '#set_source' do
    let_it_be(:source) { create(:ci_reports_sbom_source) }

    it 'stores the source' do
      report.set_source(source)

      expect(report.source).to eq(source)
    end
  end

  describe '#add_component' do
    let_it_be(:components) { create_list(:ci_reports_sbom_component, 3) }

    it 'appends components to a list' do
      components.each { |component| report.add_component(component) }

      expect(report.components).to match_array(components)
    end
  end
end