Commit fbe19e65 authored by Tetiana Chupryna's avatar Tetiana Chupryna Committed by Kamil Trzciński

Add tests for Gitlab::Vulnerabilities classes

parent c2a2b45d
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Vulnerabilities::BaseVulnerability do
let(:vulnerability) do
described_class.new(
title: 'title',
description: 'desc',
severity: 'high',
confidence: 'low',
solution: 'fix',
identifiers: '42',
links: 'link'
)
end
where(:getter) do
%w(title description severity confidence solution identifiers links)
end
with_them do
it 'raises an error' do
expect { vulnerability.public_send(getter) }.to raise_error(NotImplementedError)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Vulnerabilities::ContainerScanningVulnerability do
let(:vulnerability) { described_class.new(data) }
let(:data) do
{
vulnerability: 'vulnerability',
namespace: 'namespace',
description: 'desc',
severity: 'high',
confidence: 'low',
identifiers: '42',
links: 'link'
}
end
where(:getter) do
%i(description severity confidence solution identifiers links)
end
with_them do
it 'returns right value' do
expect(vulnerability.public_send(getter)).to eq(data[getter])
end
end
describe '#title' do
it 'composes properly' do
expect(vulnerability.title).to eq('vulnerability in namespace')
end
end
describe '#description' do
context 'without description param' do
let(:vulnerability) { described_class.new(data.without(:description)) }
subject { vulnerability.description }
it 'returns composed description' do
is_expected.to eq('**namespace** is affected by vulnerability')
end
end
describe '#solution' do
context 'without needed params' do
it 'returns empty solution' do
expect(vulnerability.solution).to be_nil
end
end
context 'with all params' do
let(:vulnerability) { described_class.new(fixedby: 'eleven', featurename: 'tardis', featureversion: 'ten') }
subject { vulnerability.solution }
it 'composes properly' do
is_expected.to eq('Upgrade **tardis** from `ten` to `eleven`')
end
end
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