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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/reports/sbom/component_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/reports/sbom/component_spec.rb70
1 files changed, 57 insertions, 13 deletions
diff --git a/spec/lib/gitlab/ci/reports/sbom/component_spec.rb b/spec/lib/gitlab/ci/reports/sbom/component_spec.rb
index 06ea3433ef0..cdaf9354104 100644
--- a/spec/lib/gitlab/ci/reports/sbom/component_spec.rb
+++ b/spec/lib/gitlab/ci/reports/sbom/component_spec.rb
@@ -1,23 +1,67 @@
# frozen_string_literal: true
-require 'fast_spec_helper'
+require 'spec_helper'
RSpec.describe Gitlab::Ci::Reports::Sbom::Component do
- let(:attributes) do
- {
- type: 'library',
- name: 'component-name',
- version: 'v0.0.1'
- }
- end
+ let(:component_type) { 'library' }
+ let(:name) { 'component-name' }
+ let(:purl_type) { 'npm' }
+ let(:purl) { Sbom::PackageUrl.new(type: purl_type, name: name, version: version).to_s }
+ let(:version) { 'v0.0.1' }
- subject { described_class.new(**attributes) }
+ subject(:component) do
+ described_class.new(
+ type: component_type,
+ name: name,
+ purl: purl,
+ version: version
+ )
+ end
it 'has correct attributes' do
- expect(subject).to have_attributes(
- component_type: attributes[:type],
- name: attributes[:name],
- version: attributes[:version]
+ expect(component).to have_attributes(
+ component_type: component_type,
+ name: name,
+ purl: an_object_having_attributes(type: purl_type),
+ version: version
)
end
+
+ describe '#ingestible?' do
+ subject { component.ingestible? }
+
+ context 'when component_type is invalid' do
+ let(:component_type) { 'invalid' }
+
+ it { is_expected.to be(false) }
+ end
+
+ context 'when purl_type is invalid' do
+ let(:purl_type) { 'invalid' }
+
+ it { is_expected.to be(false) }
+ end
+
+ context 'when component_type is valid' do
+ where(:component_type) { ::Enums::Sbom.component_types.keys.map(&:to_s) }
+
+ with_them do
+ it { is_expected.to be(true) }
+ end
+ end
+
+ context 'when purl_type is valid' do
+ where(:purl_type) { ::Enums::Sbom.purl_types.keys.map(&:to_s) }
+
+ with_them do
+ it { is_expected.to be(true) }
+ end
+ end
+
+ context 'when there is no purl' do
+ let(:purl) { nil }
+
+ it { is_expected.to be(true) }
+ end
+ end
end