Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build_repomd_xml_service_spec.rb « repository_metadata « rpm « packages « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf28301fa2c2804e421c2fea87db7ddabac8fb73 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Packages::Rpm::RepositoryMetadata::BuildRepomdXmlService 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

    context 'when data values has unexpected keys' do
      let(:data) do
        {
          filelists: described_class::ALLOWED_DATA_VALUE_KEYS.each_with_object({}) do |key, result|
            result[:"#{key}-wrong"] = { value: 'value' }
          end
        }
      end

      it 'ignores wrong keys' 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}")).to be_nil
          end
        end
      end
    end
  end
end