diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/services/packages/debian/create_package_file_service_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/services/packages/debian/create_package_file_service_spec.rb')
-rw-r--r-- | spec/services/packages/debian/create_package_file_service_spec.rb | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/spec/services/packages/debian/create_package_file_service_spec.rb b/spec/services/packages/debian/create_package_file_service_spec.rb index c8292b2d5c2..291f6df991c 100644 --- a/spec/services/packages/debian/create_package_file_service_spec.rb +++ b/spec/services/packages/debian/create_package_file_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Packages::Debian::CreatePackageFileService do include WorkhorseHelpers let_it_be(:package) { create(:debian_incoming, without_package_files: true) } + let_it_be(:current_user) { create(:user) } describe '#execute' do let(:file_name) { 'libsample0_1.2.3~alpha2_amd64.deb' } @@ -20,12 +21,13 @@ RSpec.describe Packages::Debian::CreatePackageFileService do }.with_indifferent_access end - let(:service) { described_class.new(package, params) } + let(:service) { described_class.new(package: package, current_user: current_user, params: params) } subject(:package_file) { service.execute } shared_examples 'a valid deb' do it 'creates a new package file', :aggregate_failures do + expect(::Packages::Debian::ProcessChangesWorker).not_to receive(:perform_async) expect(package_file).to be_valid expect(package_file.file.read).to start_with('!<arch>') expect(package_file.size).to eq(1124) @@ -40,6 +42,24 @@ RSpec.describe Packages::Debian::CreatePackageFileService do end end + shared_examples 'a valid changes' do + it 'creates a new package file', :aggregate_failures do + expect(::Packages::Debian::ProcessChangesWorker).to receive(:perform_async) + + expect(package_file).to be_valid + expect(package_file.file.read).to start_with('Format: 1.8') + expect(package_file.size).to eq(2143) + expect(package_file.file_name).to eq(file_name) + expect(package_file.file_sha1).to eq('54321') + expect(package_file.file_sha256).to eq('543212345') + expect(package_file.file_md5).to eq('12345') + expect(package_file.debian_file_metadatum).to be_valid + expect(package_file.debian_file_metadatum.file_type).to eq('unknown') + expect(package_file.debian_file_metadatum.architecture).to be_nil + expect(package_file.debian_file_metadatum.fields).to be_nil + end + end + context 'with temp file' do let!(:file) do upload_path = ::Packages::PackageFileUploader.workhorse_local_upload_path @@ -52,6 +72,21 @@ RSpec.describe Packages::Debian::CreatePackageFileService do end it_behaves_like 'a valid deb' + + context 'with a .changes file' do + let(:file_name) { 'sample_1.2.3~alpha2_amd64.changes' } + let(:fixture_path) { "spec/fixtures/packages/debian/#{file_name}" } + + it_behaves_like 'a valid changes' + end + + context 'when current_user is missing' do + let(:current_user) { nil } + + it 'raises an error' do + expect { package_file }.to raise_error(ArgumentError, 'Invalid user') + end + end end context 'with remote file' do @@ -77,37 +112,37 @@ RSpec.describe Packages::Debian::CreatePackageFileService do it_behaves_like 'a valid deb' end - context 'package is missing' do + context 'when package is missing' do let(:package) { nil } let(:params) { {} } it 'raises an error' do - expect { subject.execute }.to raise_error(ArgumentError, 'Invalid package') + expect { package_file }.to raise_error(ArgumentError, 'Invalid package') end end - context 'params is empty' do + context 'when params is empty' do let(:params) { {} } it 'raises an error' do - expect { subject.execute }.to raise_error(ActiveRecord::RecordInvalid) + expect { package_file }.to raise_error(ActiveRecord::RecordInvalid) end end - context 'file is missing' do + context 'when file is missing' do let(:file_name) { 'libsample0_1.2.3~alpha2_amd64.deb' } let(:file) { nil } it 'raises an error' do - expect { subject.execute }.to raise_error(ActiveRecord::RecordInvalid) + expect { package_file }.to raise_error(ActiveRecord::RecordInvalid) end end - context 'FIPS mode enabled', :fips_mode do + context 'when FIPS mode enabled', :fips_mode do let(:file) { nil } it 'raises an error' do - expect { subject.execute }.to raise_error(::Packages::FIPS::DisabledError) + expect { package_file }.to raise_error(::Packages::FIPS::DisabledError) end end end |