diff options
Diffstat (limited to 'spec/services/packages')
7 files changed, 156 insertions, 3 deletions
diff --git a/spec/services/packages/debian/parse_debian822_service_spec.rb b/spec/services/packages/debian/parse_debian822_service_spec.rb index ff146fda250..a2731816459 100644 --- a/spec/services/packages/debian/parse_debian822_service_spec.rb +++ b/spec/services/packages/debian/parse_debian822_service_spec.rb @@ -77,7 +77,7 @@ RSpec.describe Packages::Debian::ParseDebian822Service do 'Depends' => '${shlibs:Depends}, ${misc:Depends}', 'Description' => "Some mostly empty lib\nUsed in GitLab tests.\n\nTesting another paragraph." }, - 'Package: sample-udeb' => { + 'Package: sample-udeb' => { 'Package' => 'sample-udeb', 'Package-Type' => 'udeb', 'Architecture' => 'any', diff --git a/spec/services/packages/debian/process_changes_service_spec.rb b/spec/services/packages/debian/process_changes_service_spec.rb index 52bcddb6f5e..a45dd68cd6e 100644 --- a/spec/services/packages/debian/process_changes_service_spec.rb +++ b/spec/services/packages/debian/process_changes_service_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Packages::Debian::ProcessChangesService 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_it_be(:incoming) { create(:debian_incoming, project: distribution.project) } + + let!(:incoming) { create(:debian_incoming, project: distribution.project) } let(:package_file) { incoming.package_files.last } @@ -33,10 +34,11 @@ RSpec.describe Packages::Debian::ProcessChangesService do existing_package.update!(debian_distribution: distribution) end - it 'does not create a package' do + it 'does not create a package and assigns the package_file to the existing package' do expect { subject.execute } .to not_change { Packages::Package.count } .and not_change { Packages::PackageFile.count } + .and change(package_file, :package).to(existing_package) end context 'marked as pending_destruction' do diff --git a/spec/services/packages/rpm/repository_metadata/base_builder_spec.rb b/spec/services/packages/rpm/repository_metadata/base_builder_spec.rb new file mode 100644 index 00000000000..0fb58cc27d5 --- /dev/null +++ b/spec/services/packages/rpm/repository_metadata/base_builder_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Rpm::RepositoryMetadata::BaseBuilder do + describe '#execute' do + subject { described_class.new.execute } + + before do + stub_const("#{described_class}::ROOT_TAG", 'test') + stub_const("#{described_class}::ROOT_ATTRIBUTES", { foo1: 'bar1', foo2: 'bar2' }) + end + + it 'generate valid xml' do + result = Nokogiri::XML::Document.parse(subject) + + expect(result.children.count).to eq(1) + expect(result.children.first.attributes.count).to eq(2) + expect(result.children.first.attributes['foo1'].value).to eq('bar1') + expect(result.children.first.attributes['foo2'].value).to eq('bar2') + end + end +end diff --git a/spec/services/packages/rpm/repository_metadata/build_filelist_xml_spec.rb b/spec/services/packages/rpm/repository_metadata/build_filelist_xml_spec.rb new file mode 100644 index 00000000000..2feb44c7c1b --- /dev/null +++ b/spec/services/packages/rpm/repository_metadata/build_filelist_xml_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Rpm::RepositoryMetadata::BuildFilelistXml do + describe '#execute' do + subject { described_class.new.execute } + + context "when generate empty xml" do + let(:expected_xml) do + <<~XML + <?xml version="1.0" encoding="UTF-8"?> + <filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="0"/> + XML + end + + it 'generate expected xml' do + expect(subject).to eq(expected_xml) + end + end + end +end diff --git a/spec/services/packages/rpm/repository_metadata/build_other_xml_spec.rb b/spec/services/packages/rpm/repository_metadata/build_other_xml_spec.rb new file mode 100644 index 00000000000..823aa18808a --- /dev/null +++ b/spec/services/packages/rpm/repository_metadata/build_other_xml_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Rpm::RepositoryMetadata::BuildOtherXml do + describe '#execute' do + subject { described_class.new.execute } + + context "when generate empty xml" do + let(:expected_xml) do + <<~XML + <?xml version="1.0" encoding="UTF-8"?> + <otherdata xmlns="http://linux.duke.edu/metadata/other" packages="0"/> + XML + end + + it 'generate expected xml' do + expect(subject).to eq(expected_xml) + end + end + end +end diff --git a/spec/services/packages/rpm/repository_metadata/build_primary_xml_spec.rb b/spec/services/packages/rpm/repository_metadata/build_primary_xml_spec.rb new file mode 100644 index 00000000000..f5294d6f7f7 --- /dev/null +++ b/spec/services/packages/rpm/repository_metadata/build_primary_xml_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Rpm::RepositoryMetadata::BuildPrimaryXml do + describe '#execute' do + subject { described_class.new.execute } + + context "when generate empty xml" do + let(:expected_xml) do + <<~XML + <?xml version="1.0" encoding="UTF-8"?> + <metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="0"/> + XML + end + + it 'generate expected xml' do + expect(subject).to eq(expected_xml) + end + end + end +end diff --git a/spec/services/packages/rpm/repository_metadata/build_repomd_xml_spec.rb b/spec/services/packages/rpm/repository_metadata/build_repomd_xml_spec.rb new file mode 100644 index 00000000000..29b0f73e3c1 --- /dev/null +++ b/spec/services/packages/rpm/repository_metadata/build_repomd_xml_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Packages::Rpm::RepositoryMetadata::BuildRepomdXml do + describe '#execute' do + subject { described_class.new(data).execute } + + let(:data) do + { + filelists: { + checksum: { type: "sha256", value: "123" }, + 'open-checksum': { type: "sha256", value: "123" }, + location: { href: "repodata/123-filelists.xml.gz" }, + timestamp: { value: 1644602784 }, + size: { value: 11111 }, + 'open-size': { value: 11111 } + }, + primary: { + checksum: { type: "sha256", value: "234" }, + 'open-checksum': { type: "sha256", value: "234" }, + location: { href: "repodata/234-primary.xml.gz" }, + timestamp: { value: 1644602784 }, + size: { value: 22222 }, + 'open-size': { value: 22222 } + }, + other: { + checksum: { type: "sha256", value: "345" }, + 'open-checksum': { type: "sha256", value: "345" }, + location: { href: "repodata/345-other.xml.gz" }, + timestamp: { value: 1644602784 }, + size: { value: 33333 }, + 'open-size': { value: 33333 } + } + } + end + + let(:creation_timestamp) { 111111 } + + before do + allow(Time).to receive(:now).and_return(creation_timestamp) + end + + it 'generate valid xml' do + # Have one root attribute + result = Nokogiri::XML::Document.parse(subject) + expect(result.children.count).to eq(1) + + # Root attribute name is 'repomd' + root = result.children.first + expect(root.name).to eq('repomd') + + # Have the same count of 'data' tags as count of keys in 'data' + expect(result.css('data').count).to eq(data.count) + end + + it 'has all data info' do + result = Nokogiri::XML::Document.parse(subject).remove_namespaces! + + data.each do |tag_name, tag_attributes| + tag_attributes.each_key do |key| + expect(result.at("//repomd/data[@type=\"#{tag_name}\"]/#{key}")).not_to be_nil + end + end + end + end +end |