diff options
Diffstat (limited to 'spec/services/packages/rpm')
5 files changed, 151 insertions, 0 deletions
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 |