summaryrefslogtreecommitdiff
path: root/spec/services/packages/debian/process_package_file_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/packages/debian/process_package_file_service_spec.rb')
-rw-r--r--spec/services/packages/debian/process_package_file_service_spec.rb167
1 files changed, 98 insertions, 69 deletions
diff --git a/spec/services/packages/debian/process_package_file_service_spec.rb b/spec/services/packages/debian/process_package_file_service_spec.rb
index 571861f42cf..caf29cfc4fa 100644
--- a/spec/services/packages/debian/process_package_file_service_spec.rb
+++ b/spec/services/packages/debian/process_package_file_service_spec.rb
@@ -1,20 +1,33 @@
# frozen_string_literal: true
require 'spec_helper'
-RSpec.describe Packages::Debian::ProcessPackageFileService do
+RSpec.describe Packages::Debian::ProcessPackageFileService, feature_category: :package_registry do
describe '#execute' do
- let_it_be(:user) { create(:user) }
- let_it_be_with_reload(:distribution) { create(:debian_project_distribution, :with_file, codename: 'unstable') }
-
- let!(:incoming) { create(:debian_incoming, project: distribution.project) }
+ let_it_be_with_reload(:distribution) { create(:debian_project_distribution, :with_suite, :with_file) }
+ let!(:package) { create(:debian_package, :processing, project: distribution.project, published_in: nil) }
let(:distribution_name) { distribution.codename }
+ let(:component_name) { 'main' }
let(:debian_file_metadatum) { package_file.debian_file_metadatum }
- subject { described_class.new(package_file, user, distribution_name, component_name) }
+ subject { described_class.new(package_file, distribution_name, component_name) }
- RSpec.shared_context 'with Debian package file' do |file_name|
- let(:package_file) { incoming.package_files.with_file_name(file_name).first }
+ shared_examples 'updates package and package file' do
+ it 'updates package and package file', :aggregate_failures do
+ expect(::Packages::Debian::GenerateDistributionWorker)
+ .to receive(:perform_async).with(:project, distribution.id)
+ expect { subject.execute }
+ .to not_change(Packages::Package, :count)
+ .and not_change(Packages::PackageFile, :count)
+ .and change(Packages::Debian::Publication, :count).by(1)
+ .and not_change(package.package_files, :count)
+ .and change { package.reload.name }.to('sample')
+ .and change { package.reload.version }.to('1.2.3~alpha2')
+ .and change { package.reload.status }.from('processing').to('default')
+ .and change { package.reload.debian_publication }.from(nil)
+ .and change(debian_file_metadatum, :file_type).from('unknown').to(expected_file_type)
+ .and change(debian_file_metadatum, :component).from(nil).to(component_name)
+ end
end
using RSpec::Parameterized::TableSyntax
@@ -25,59 +38,68 @@ RSpec.describe Packages::Debian::ProcessPackageFileService do
end
with_them do
- include_context 'with Debian package file', params[:file_name] do
- it 'creates package and updates package file', :aggregate_failures do
- expect(::Packages::Debian::GenerateDistributionWorker)
- .to receive(:perform_async).with(:project, distribution.id)
- expect { subject.execute }
- .to change(Packages::Package, :count).from(1).to(2)
- .and not_change(Packages::PackageFile, :count)
- .and change(incoming.package_files, :count).from(7).to(6)
- .and change(debian_file_metadatum, :file_type).from('unknown').to(expected_file_type)
- .and change(debian_file_metadatum, :component).from(nil).to(component_name)
-
- created_package = Packages::Package.last
- expect(created_package.name).to eq 'sample'
- expect(created_package.version).to eq '1.2.3~alpha2'
- expect(created_package.creator).to eq user
- end
+ context 'with Debian package file' do
+ let(:package_file) { package.package_files.with_file_name(file_name).first }
- context 'with existing package' do
- let_it_be_with_reload(:existing_package) do
- create(:debian_package, name: 'sample', version: '1.2.3~alpha2', project: distribution.project)
+ context 'when there is no matching published package' do
+ it_behaves_like 'updates package and package file'
+
+ context 'with suite as distribution name' do
+ let(:distribution_name) { distribution.suite }
+
+ it_behaves_like 'updates package and package file'
end
+ end
- before do
- existing_package.update!(debian_distribution: distribution)
+ context 'when there is a matching published package' do
+ let!(:matching_package) do
+ create(
+ :debian_package,
+ project: distribution.project,
+ published_in: distribution,
+ name: 'sample',
+ version: '1.2.3~alpha2'
+ )
end
- it 'does not create a package and assigns the package_file to the existing package' do
+ it 'reuses existing package and update package file', :aggregate_failures do
expect(::Packages::Debian::GenerateDistributionWorker)
.to receive(:perform_async).with(:project, distribution.id)
expect { subject.execute }
- .to not_change(Packages::Package, :count)
- .and not_change(Packages::PackageFile, :count)
- .and change(incoming.package_files, :count).from(7).to(6)
- .and change(package_file, :package).from(incoming).to(existing_package)
- .and change(debian_file_metadatum, :file_type).from('unknown').to(expected_file_type.to_s)
+ .to change(Packages::Package, :count).from(2).to(1)
+ .and change(Packages::PackageFile, :count).from(14).to(8)
+ .and not_change(Packages::Debian::Publication, :count)
+ .and change(package.package_files, :count).from(7).to(0)
+ .and change(package_file, :package).from(package).to(matching_package)
+ .and not_change(matching_package, :name)
+ .and not_change(matching_package, :version)
+ .and change(debian_file_metadatum, :file_type).from('unknown').to(expected_file_type)
.and change(debian_file_metadatum, :component).from(nil).to(component_name)
- end
- context 'when marked as pending_destruction' do
- it 'does not re-use the existing package' do
- existing_package.pending_destruction!
+ expect { package.reload }
+ .to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
- expect { subject.execute }
- .to change(Packages::Package, :count).by(1)
- .and not_change(Packages::PackageFile, :count)
- end
+ context 'when there is a matching published package pending destruction' do
+ let!(:matching_package) do
+ create(
+ :debian_package,
+ :pending_destruction,
+ project: distribution.project,
+ published_in: distribution,
+ name: 'sample',
+ version: '1.2.3~alpha2'
+ )
end
+
+ it_behaves_like 'updates package and package file'
end
end
end
context 'without a distribution' do
- let(:package_file) { incoming.package_files.with_file_name('libsample0_1.2.3~alpha2_amd64.deb').first }
+ let(:package_file) { package.package_files.with_file_name('libsample0_1.2.3~alpha2_amd64.deb').first }
let(:component_name) { 'main' }
before do
@@ -89,42 +111,41 @@ RSpec.describe Packages::Debian::ProcessPackageFileService do
expect { subject.execute }
.to not_change(Packages::Package, :count)
.and not_change(Packages::PackageFile, :count)
- .and not_change(incoming.package_files, :count)
+ .and not_change(package.package_files, :count)
.and raise_error(ActiveRecord::RecordNotFound)
end
end
- context 'with package file without Debian metadata' do
+ context 'without distribution name' do
let!(:package_file) { create(:debian_package_file, without_loaded_metadatum: true) }
- let(:component_name) { 'main' }
+ let(:distribution_name) { '' }
it 'raise ArgumentError', :aggregate_failures do
expect(::Packages::Debian::GenerateDistributionWorker).not_to receive(:perform_async)
expect { subject.execute }
.to not_change(Packages::Package, :count)
.and not_change(Packages::PackageFile, :count)
- .and not_change(incoming.package_files, :count)
- .and raise_error(ArgumentError, 'package file without Debian metadata')
+ .and not_change(package.package_files, :count)
+ .and raise_error(ArgumentError, 'missing distribution name')
end
end
- context 'with already processed package file' do
- let_it_be(:package_file) { create(:debian_package_file) }
-
- let(:component_name) { 'main' }
+ context 'without component name' do
+ let!(:package_file) { create(:debian_package_file, without_loaded_metadatum: true) }
+ let(:component_name) { '' }
it 'raise ArgumentError', :aggregate_failures do
expect(::Packages::Debian::GenerateDistributionWorker).not_to receive(:perform_async)
expect { subject.execute }
.to not_change(Packages::Package, :count)
.and not_change(Packages::PackageFile, :count)
- .and not_change(incoming.package_files, :count)
- .and raise_error(ArgumentError, 'already processed package file')
+ .and not_change(package.package_files, :count)
+ .and raise_error(ArgumentError, 'missing component name')
end
end
- context 'with invalid package file type' do
- let(:package_file) { incoming.package_files.with_file_name('sample_1.2.3~alpha2.tar.xz').first }
+ context 'with package file without Debian metadata' do
+ let!(:package_file) { create(:debian_package_file, without_loaded_metadatum: true) }
let(:component_name) { 'main' }
it 'raise ArgumentError', :aggregate_failures do
@@ -132,29 +153,37 @@ RSpec.describe Packages::Debian::ProcessPackageFileService do
expect { subject.execute }
.to not_change(Packages::Package, :count)
.and not_change(Packages::PackageFile, :count)
- .and not_change(incoming.package_files, :count)
- .and raise_error(ArgumentError, 'invalid package file type: source')
+ .and not_change(package.package_files, :count)
+ .and raise_error(ArgumentError, 'package file without Debian metadata')
end
end
- context 'when creating package fails' do
- let(:package_file) { incoming.package_files.with_file_name('libsample0_1.2.3~alpha2_amd64.deb').first }
+ context 'with already processed package file' do
+ let_it_be(:package_file) { create(:debian_package_file) }
+
let(:component_name) { 'main' }
- before do
- allow_next_instance_of(::Packages::Debian::FindOrCreatePackageService) do |find_or_create_package_service|
- allow(find_or_create_package_service)
- .to receive(:execute).and_raise(ActiveRecord::ConnectionTimeoutError, 'connect timeout')
- end
+ it 'raise ArgumentError', :aggregate_failures do
+ expect(::Packages::Debian::GenerateDistributionWorker).not_to receive(:perform_async)
+ expect { subject.execute }
+ .to not_change(Packages::Package, :count)
+ .and not_change(Packages::PackageFile, :count)
+ .and not_change(package.package_files, :count)
+ .and raise_error(ArgumentError, 'already processed package file')
end
+ end
- it 're-raise error', :aggregate_failures do
+ context 'with invalid package file type' do
+ let(:package_file) { package.package_files.with_file_name('sample_1.2.3~alpha2.tar.xz').first }
+ let(:component_name) { 'main' }
+
+ it 'raise ArgumentError', :aggregate_failures do
expect(::Packages::Debian::GenerateDistributionWorker).not_to receive(:perform_async)
expect { subject.execute }
.to not_change(Packages::Package, :count)
.and not_change(Packages::PackageFile, :count)
- .and not_change(incoming.package_files, :count)
- .and raise_error(ActiveRecord::ConnectionTimeoutError, 'connect timeout')
+ .and not_change(package.package_files, :count)
+ .and raise_error(ArgumentError, 'invalid package file type: source')
end
end
end