Welcome to mirror list, hosted at ThFree Co, Russian Federation.

report_spec.rb « sbom « reports « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7a285ab13c1fa611b415ff228ddfb5adacbffc1 (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
52
53
54
# frozen_string_literal: true

require 'spec_helper'

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

  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) do
      {
        'type' => :dependency_scanning,
        'data' => {
          'input_file' => { 'path' => 'package-lock.json' },
          'source_file' => { 'path' => 'package.json' },
          'package_manager' => { 'name' => 'npm' },
          'language' => { 'name' => 'JavaScript' }
        },
        'fingerprint' => 'c01df1dc736c1148717e053edbde56cb3a55d3e31f87cea955945b6f67c17d42'
      }
    end

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

      expect(report.source).to be_a(Gitlab::Ci::Reports::Sbom::Source)
    end
  end

  describe '#add_component' do
    let_it_be(:components) do
      [
        { 'type' => 'library', 'name' => 'component1', 'version' => 'v0.0.1' },
        { 'type' => 'library', 'name' => 'component2', 'version' => 'v0.0.2' },
        { 'type' => 'library', 'name' => 'component2' }
      ]
    end

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

      expect(report.components.size).to eq(3)
      expect(report.components).to all(be_a(Gitlab::Ci::Reports::Sbom::Component))
    end
  end
end