diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-13 15:10:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-13 15:10:07 +0300 |
commit | df592d51aeadc1b566abb600e283341876a8f064 (patch) | |
tree | 6b9acbcf1da5c40cceece035b0126a354f68650a /spec/services/packages/nuget | |
parent | 7ece9a7935fca35a8d91d2cb29bfad453b69be12 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/packages/nuget')
5 files changed, 36 insertions, 53 deletions
diff --git a/spec/services/packages/nuget/check_duplicates_service_spec.rb b/spec/services/packages/nuget/check_duplicates_service_spec.rb index 9675aa5f5e2..6274036800a 100644 --- a/spec/services/packages/nuget/check_duplicates_service_spec.rb +++ b/spec/services/packages/nuget/check_duplicates_service_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe Packages::Nuget::CheckDuplicatesService, feature_category: :package_registry do - include PackagesManagerApiSpecHelpers - let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:file_name) { 'package.nupkg' } @@ -12,7 +10,7 @@ RSpec.describe Packages::Nuget::CheckDuplicatesService, feature_category: :packa let(:params) do { file_name: file_name, - file: temp_file(file_name) + file: File.open(expand_fixture_path('packages/nuget/package.nupkg')) } end diff --git a/spec/services/packages/nuget/extract_metadata_file_service_spec.rb b/spec/services/packages/nuget/extract_metadata_file_service_spec.rb index 4c761826b53..ac5749c2dc4 100644 --- a/spec/services/packages/nuget/extract_metadata_file_service_spec.rb +++ b/spec/services/packages/nuget/extract_metadata_file_service_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Packages::Nuget::ExtractMetadataFileService, feature_category: :package_registry do + include PackagesManagerApiSpecHelpers + let_it_be(:package_file) { build(:package_file, :nuget) } let_it_be(:package_zip_file) { Zip::File.new(package_file.file) } @@ -38,6 +40,18 @@ RSpec.describe Packages::Nuget::ExtractMetadataFileService, feature_category: :p it 'returns the nuspec file content' do expect(subject.payload.squish).to include(expected_metadata) end + + context 'with InputStream zip' do + let(:package_zip_file) do + Zip::InputStream.open( + temp_file('package.nupkg', content: File.open(package_file.file.path)) + ) + end + + it 'returns the nuspec file content' do + expect(subject.payload.squish).to include(expected_metadata) + end + end end context 'without the nuspec file' do diff --git a/spec/services/packages/nuget/metadata_extraction_service_spec.rb b/spec/services/packages/nuget/metadata_extraction_service_spec.rb index 81a4e4a430b..46d5449d52b 100644 --- a/spec/services/packages/nuget/metadata_extraction_service_spec.rb +++ b/spec/services/packages/nuget/metadata_extraction_service_spec.rb @@ -4,7 +4,8 @@ require 'spec_helper' RSpec.describe Packages::Nuget::MetadataExtractionService, feature_category: :package_registry do let_it_be(:package_file) { build(:package_file, :nuget) } - let(:service) { described_class.new(package_file) } + let(:package_zip_file) { Zip::File.new(package_file.file) } + let(:service) { described_class.new(package_zip_file) } describe '#execute' do subject { service.execute } @@ -50,8 +51,8 @@ RSpec.describe Packages::Nuget::MetadataExtractionService, feature_category: :pa end it 'calls the necessary services and executes the metadata extraction' do - expect_next_instance_of(Packages::Nuget::ProcessPackageFileService, package_file) do |service| - expect(service).to receive(:execute).and_return(ServiceResponse.success(payload: { nuspec_file_content: nuspec_file_content })) + expect_next_instance_of(Packages::Nuget::ExtractMetadataFileService, package_zip_file) do |service| + expect(service).to receive(:execute).and_return(ServiceResponse.success(payload: nuspec_file_content)) end expect_next_instance_of(Packages::Nuget::ExtractMetadataContentService, nuspec_file_content) do |service| diff --git a/spec/services/packages/nuget/process_package_file_service_spec.rb b/spec/services/packages/nuget/process_package_file_service_spec.rb index cdeb5b32737..70e8bcb8c5c 100644 --- a/spec/services/packages/nuget/process_package_file_service_spec.rb +++ b/spec/services/packages/nuget/process_package_file_service_spec.rb @@ -14,25 +14,14 @@ RSpec.describe Packages::Nuget::ProcessPackageFileService, feature_category: :pa it { expect { subject }.to raise_error(described_class::ExtractionError, error_message) } end - shared_examples 'not creating a symbol file' do - it 'does not call the CreateSymbolFilesService' do - expect(Packages::Nuget::Symbols::CreateSymbolFilesService).not_to receive(:new) - - expect(subject).to be_success - end - end - context 'with valid package file' do - it 'calls the ExtractMetadataFileService' do - expect_next_instance_of(Packages::Nuget::ExtractMetadataFileService, instance_of(Zip::File)) do |service| - expect(service).to receive(:execute) do - instance_double(ServiceResponse).tap do |response| - expect(response).to receive(:payload).and_return(instance_of(String)) - end - end + it 'calls the UpdatePackageFromMetadataService' do + expect_next_instance_of(Packages::Nuget::UpdatePackageFromMetadataService, package_file, + instance_of(Zip::File)) do |service| + expect(service).to receive(:execute) end - expect(subject).to be_success + subject end end @@ -59,25 +48,5 @@ RSpec.describe Packages::Nuget::ProcessPackageFileService, feature_category: :pa it_behaves_like 'raises an error', 'invalid package file' end - - context 'with a symbol package file' do - let(:package_file) { build(:package_file, :snupkg) } - - it 'calls the CreateSymbolFilesService' do - expect_next_instance_of( - Packages::Nuget::Symbols::CreateSymbolFilesService, package_file.package, instance_of(Zip::File) - ) do |service| - expect(service).to receive(:execute) - end - - expect(subject).to be_success - end - end - - context 'with a non symbol package file' do - let(:package_file) { build(:package_file, :nuget) } - - it_behaves_like 'not creating a symbol file' - end end end diff --git a/spec/services/packages/nuget/update_package_from_metadata_service_spec.rb b/spec/services/packages/nuget/update_package_from_metadata_service_spec.rb index c199afcf2ca..0e19f2ac3f9 100644 --- a/spec/services/packages/nuget/update_package_from_metadata_service_spec.rb +++ b/spec/services/packages/nuget/update_package_from_metadata_service_spec.rb @@ -7,7 +7,8 @@ RSpec.describe Packages::Nuget::UpdatePackageFromMetadataService, :clean_gitlab_ let!(:package) { create(:nuget_package, :processing, :with_symbol_package, :with_build) } let(:package_file) { package.package_files.first } - let(:service) { described_class.new(package_file) } + let(:package_zip_file) { Zip::File.new(package_file.file) } + let(:service) { described_class.new(package_file, package_zip_file) } let(:package_name) { 'DummyProject.DummyPackage' } let(:package_version) { '1.0.0' } let(:package_file_name) { 'dummyproject.dummypackage.1.0.0.nupkg' } @@ -247,11 +248,20 @@ RSpec.describe Packages::Nuget::UpdatePackageFromMetadataService, :clean_gitlab_ context 'with existing package' do let!(:existing_package) { create(:nuget_package, project: package.project, name: package_name, version: package_version) } let(:package_id) { existing_package.id } + let(:package_zip_file) do + Zip::File.open(package_file.file.path) do |zipfile| + zipfile.add('package.pdb', expand_fixture_path('packages/nuget/symbol/package.pdb')) + zipfile + end + end it 'link existing package and updates package file', :aggregate_failures do expect(service).to receive(:try_obtain_lease).and_call_original expect(::Packages::Nuget::SyncMetadatumService).not_to receive(:new) expect(::Packages::UpdateTagsService).not_to receive(:new) + expect_next_instance_of(Packages::Nuget::Symbols::CreateSymbolFilesService, existing_package, package_zip_file) do |service| + expect(service).to receive(:execute).and_call_original + end expect { subject } .to change { ::Packages::Package.count }.by(-1) @@ -259,20 +269,11 @@ RSpec.describe Packages::Nuget::UpdatePackageFromMetadataService, :clean_gitlab_ .and change { Packages::DependencyLink.count }.by(0) .and change { Packages::Nuget::DependencyLinkMetadatum.count }.by(0) .and change { ::Packages::Nuget::Metadatum.count }.by(0) + .and change { existing_package.nuget_symbols.count }.by(1) expect(package_file.reload.file_name).to eq(package_file_name) expect(package_file.package).to eq(existing_package) end - context 'with packages_nuget_symbols records' do - before do - create_list(:nuget_symbol, 2, package: package) - end - - it 'links the symbol records to the existing package' do - expect { subject }.to change { existing_package.nuget_symbols.count }.by(2) - end - end - it_behaves_like 'taking the lease' it_behaves_like 'not updating the package if the lease is taken' |