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/workers/packages/nuget/extraction_worker_spec.rb')
-rw-r--r--spec/workers/packages/nuget/extraction_worker_spec.rb126
1 files changed, 84 insertions, 42 deletions
diff --git a/spec/workers/packages/nuget/extraction_worker_spec.rb b/spec/workers/packages/nuget/extraction_worker_spec.rb
index 11eaa1b5dde..d261002a339 100644
--- a/spec/workers/packages/nuget/extraction_worker_spec.rb
+++ b/spec/workers/packages/nuget/extraction_worker_spec.rb
@@ -13,16 +13,21 @@ RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker, feature_categor
subject { described_class.new.perform(package_file_id) }
- shared_examples 'handling the metadata error' do |exception_class: ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError|
+ shared_examples 'handling error' do |error_message:,
+ error_class: ::Packages::Nuget::UpdatePackageFromMetadataService::InvalidMetadataError|
it 'updates package status to error', :aggregate_failures do
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
- instance_of(exception_class),
- project_id: package.project_id
+ instance_of(error_class),
+ {
+ package_file_id: package_file.id,
+ project_id: package.project_id
+ }
)
subject
expect(package.reload).to be_error
+ expect(package.status_message).to match(error_message)
end
end
@@ -56,64 +61,101 @@ RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker, feature_categor
end
end
- context 'with package file not containing a nuspec file' do
- before do
- allow_any_instance_of(Zip::File).to receive(:glob).and_return([])
- end
-
- it_behaves_like 'handling the metadata error', exception_class: ::Packages::Nuget::ExtractMetadataFileService::ExtractionError
- end
+ context 'with controlled errors' do
+ context 'with package file not containing a nuspec file' do
+ before do
+ allow_any_instance_of(Zip::File).to receive(:glob).and_return([])
+ end
- context 'with package with an invalid package name' do
- invalid_names = [
- '',
- 'My/package',
- '../../../my_package',
- '%2e%2e%2fmy_package'
- ]
+ it_behaves_like 'handling error',
+ error_class: ::Packages::Nuget::ExtractMetadataFileService::ExtractionError,
+ error_message: 'nuspec file not found'
+ end
- invalid_names.each do |invalid_name|
- context "with #{invalid_name}" do
+ context 'with invalid metadata' do
+ shared_context 'with a blank attribute' do
before do
allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service|
- allow(service).to receive(:package_name).and_return(invalid_name)
+ allow(service).to receive(attribute).and_return('')
end
end
+ end
+
+ context 'with a blank package name' do
+ include_context 'with a blank attribute' do
+ let(:attribute) { :package_name }
- it_behaves_like 'handling the metadata error'
+ it_behaves_like 'handling error', error_message: /not found in metadata/
+ end
end
- end
- end
- context 'with package with an invalid package version' do
- invalid_versions = [
- '',
- '555',
- '1./2.3',
- '../../../../../1.2.3',
- '%2e%2e%2f1.2.3'
- ]
-
- invalid_versions.each do |invalid_version|
- context "with #{invalid_version}" do
- before do
- allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service|
- allow(service).to receive(:package_version).and_return(invalid_version)
+ context 'with package with an invalid package name' do
+ invalid_names = [
+ 'My/package',
+ '../../../my_package',
+ '%2e%2e%2fmy_package'
+ ]
+
+ invalid_names.each do |invalid_name|
+ context "with #{invalid_name}" do
+ before do
+ allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service|
+ allow(service).to receive(:package_name).and_return(invalid_name)
+ end
+ end
+
+ it_behaves_like 'handling error', error_message: 'Validation failed: Name is invalid'
+ end
+ end
+ end
+
+ context 'with package with a blank package version' do
+ include_context 'with a blank attribute' do
+ let(:attribute) { :package_version }
+
+ it_behaves_like 'handling error', error_message: /not found in metadata/
+ end
+ end
+
+ context 'with package with an invalid package version' do
+ invalid_versions = [
+ '555',
+ '1./2.3',
+ '../../../../../1.2.3',
+ '%2e%2e%2f1.2.3'
+ ]
+
+ invalid_versions.each do |invalid_version|
+ context "with #{invalid_version}" do
+ before do
+ allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service|
+ allow(service).to receive(:package_version).and_return(invalid_version)
+ end
+ end
+
+ it_behaves_like 'handling error', error_message: 'Validation failed: Version is invalid'
end
end
+ end
+ end
- it_behaves_like 'handling the metadata error'
+ context 'handling a Zip::Error exception' do
+ before do
+ allow_any_instance_of(::Packages::UpdatePackageFileService).to receive(:execute).and_raise(::Zip::Error)
end
+
+ it_behaves_like 'handling error',
+ error_class: ::Packages::Nuget::UpdatePackageFromMetadataService::ZipError,
+ error_message: 'Could not open the .nupkg file'
end
end
- context 'handles a processing an unaccounted for error' do
+ context 'with uncontrolled errors' do
before do
- expect(::Packages::Nuget::UpdatePackageFromMetadataService).to receive(:new)
- .and_raise(Zip::Error)
+ allow_any_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService).to receive(:execute).and_raise(StandardError.new('Boom'))
end
- it_behaves_like 'handling the metadata error', exception_class: Zip::Error
+ it_behaves_like 'handling error', error_class: StandardError, error_message: 'Unexpected error: StandardError'
end
end
end