summaryrefslogtreecommitdiff
path: root/spec/services/packages/rpm/repository_metadata/build_repomd_xml_spec.rb
blob: 29b0f73e3c1b1b44a5f7a9c6e534d21d8323de80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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