debian-mirror-gitlab/spec/services/packages/debian/extract_metadata_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
3.8 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
2023-05-27 22:25:52 +05:30
2021-03-08 18:12:59 +05:30
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Packages::Debian::ExtractMetadataService, feature_category: :package_registry do
2021-03-08 18:12:59 +05:30
let(:service) { described_class.new(package_file) }
subject { service.execute }
2023-05-27 22:25:52 +05:30
RSpec.shared_context 'with Debian package file' do |trait|
2021-03-08 18:12:59 +05:30
let(:package_file) { create(:debian_package_file, trait) }
end
RSpec.shared_examples 'Test Debian ExtractMetadata Service' do |expected_file_type, expected_architecture, expected_fields|
2023-05-27 22:25:52 +05:30
it "returns file_type #{expected_file_type.inspect}, architecture #{expected_architecture.inspect} and fields #{expected_fields.nil? ? '' : 'including '}#{expected_fields.inspect}",
:aggregate_failures do
2021-03-08 18:12:59 +05:30
expect(subject[:file_type]).to eq(expected_file_type)
expect(subject[:architecture]).to eq(expected_architecture)
if expected_fields.nil?
expect(subject[:fields]).to be_nil
else
expect(subject[:fields]).to include(**expected_fields)
end
end
end
using RSpec::Parameterized::TableSyntax
2023-05-27 22:25:52 +05:30
context 'with valid file types' do
where(:case_name, :trait, :expected_file_type, :expected_architecture, :expected_fields) do
'with source' | :source | :source | nil | nil
'with dsc' | :dsc | :dsc | nil | { 'Binary' => 'sample-dev, libsample0, sample-udeb, sample-ddeb' }
'with deb' | :deb | :deb | 'amd64' | { 'Multi-Arch' => 'same' }
'with udeb' | :udeb | :udeb | 'amd64' | { 'Package' => 'sample-udeb' }
'with ddeb' | :ddeb | :ddeb | 'amd64' | { 'Package' => 'sample-ddeb' }
'with buildinfo' | :buildinfo | :buildinfo | nil | { 'Architecture' => 'amd64 source',
'Build-Architecture' => 'amd64' }
'with changes' | :changes | :changes | nil | { 'Architecture' => 'source amd64',
'Binary' => 'libsample0 sample-dev sample-udeb' }
end
with_them do
include_context 'with Debian package file', params[:trait] do
it_behaves_like 'Test Debian ExtractMetadata Service',
params[:expected_file_type],
params[:expected_architecture],
params[:expected_fields]
end
end
2021-03-08 18:12:59 +05:30
end
2023-05-27 22:25:52 +05:30
context 'with valid source extensions' do
where(:ext) do
%i[gz bz2 lzma xz]
end
with_them do
let(:package_file) do
create(:debian_package_file, :source, file_name: "myfile.tar.#{ext}",
file_fixture: 'spec/fixtures/packages/debian/sample_1.2.3~alpha2.tar.xz')
end
it_behaves_like 'Test Debian ExtractMetadata Service', :source
end
end
context 'with invalid source extensions' do
where(:ext) do
%i[gzip bzip2]
end
with_them do
let(:package_file) do
create(:debian_package_file, :source, file_name: "myfile.tar.#{ext}",
file_fixture: 'spec/fixtures/packages/debian/sample_1.2.3~alpha2.tar.xz')
end
it 'raises an error' do
expect do
subject
end.to raise_error(described_class::ExtractionError,
"unsupported file extension for file #{package_file.file_name}")
end
end
end
context 'with invalid file name' do
let(:package_file) { create(:debian_package_file, :invalid) }
it 'raises an error' do
expect do
subject
end.to raise_error(described_class::ExtractionError,
"unsupported file extension for file #{package_file.file_name}")
2021-03-08 18:12:59 +05:30
end
end
context 'with invalid package file' do
let(:package_file) { create(:conan_package_file) }
2023-05-27 22:25:52 +05:30
it 'raises an error' do
2021-03-08 18:12:59 +05:30
expect { subject }.to raise_error(described_class::ExtractionError, 'invalid package file')
end
end
end