summaryrefslogtreecommitdiff
path: root/tests/test_profile.py
blob: 75da1d50564bc7cf8071e0e8ea26b0a6108ff5f7 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# gemato: Profile behavior tests
# vim:fileencoding=utf-8
# (c) 2017 Michał Górny
# Licensed under the terms of 2-clause BSD license

import os.path

import gemato.profile
import gemato.recursiveloader

from tests.testutil import TempDirTestCase


class EbuildRepositoryTests(TempDirTestCase):
    """
    Tests for ebuild repository profiles.
    """

    PROFILE = gemato.profile.EbuildRepositoryProfile
    DIRS = [
        'dev-foo',
        'dev-foo/bar',
        'dev-foo/bar/files',
        'eclass',
        'eclass/tests',
        'licenses',
        'metadata',
        'metadata/dtd',
        'metadata/glsa',
        'metadata/install-qa-check.d',
        'metadata/md5-cache',
        'metadata/md5-cache/dev-foo',
        'metadata/news',
        'metadata/news/2020-01-01-foo',
        'metadata/xml-schema',
        'profiles',
        'profiles/arch',
        'profiles/arch/foo',
        'profiles/desc',
        'profiles/updates',
    ]
    EXPECTED_MANIFESTS = [
        'dev-foo/Manifest',
        'dev-foo/bar/Manifest',
        'eclass/Manifest',
        'licenses/Manifest',
        'metadata/Manifest',
        'metadata/glsa/Manifest',
        'metadata/md5-cache/Manifest',
        'metadata/md5-cache/dev-foo/Manifest',
        'metadata/news/Manifest',
        'profiles/Manifest',
    ]
    EXPECTED_TYPES = {
        'header.txt': 'DATA',
        'skel.ebuild': 'DATA',
        'skel.metadata.xml': 'DATA',
        'dev-foo/metadata.xml': 'DATA',
        'dev-foo/bar/bar-1.ebuild': 'DATA',
        'dev-foo/bar/metadata.xml': 'DATA',
        'dev-foo/bar/files/test.patch': 'DATA',
        'eclass/foo.eclass': 'DATA',
        'eclass/tests/foo.sh': 'DATA',
        'licenses/foo': 'DATA',
        'metadata/layout.conf': 'DATA',
        'metadata/projects.xml': 'DATA',
        'metadata/pkg_desc_index': 'DATA',
        'metadata/timestamp': 'DATA',
        'metadata/timestamp.chk': 'DATA',
        'metadata/timestamp.commit': 'DATA',
        'metadata/timestamp.x': 'DATA',
        'metadata/dtd/foo.dtd': 'DATA',
        'metadata/glsa/glsa-202001-01.xml': 'DATA',
        'metadata/install-qa-check.d/50foo': 'DATA',
        'metadata/md5-cache/dev-foo/bar-1': 'DATA',
        'metadata/news/2020-01-01-foo/2020-01-01-foo.en.txt': 'DATA',
        'metadata/news/2020-01-01-foo/2020-01-01-foo.en.txt.asc': 'DATA',
        'metadata/xml-schema/foo.xsd': 'DATA',
        'profiles/arch.desc': 'DATA',
        'profiles/categories': 'DATA',
        'profiles/eapi': 'DATA',
        'profiles/info_pkgs': 'DATA',
        'profiles/info_vars': 'DATA',
        'profiles/license_groups': 'DATA',
        'profiles/package.mask': 'DATA',
        'profiles/profiles.desc': 'DATA',
        'profiles/repo_name': 'DATA',
        'profiles/thirdpartymirrors': 'DATA',
        'profiles/use.desc': 'DATA',
        'profiles/use.local.desc': 'DATA',
        'profiles/arch/foo/eapi': 'DATA',
        'profiles/arch/foo/parent': 'DATA',
        'profiles/desc/foo.desc': 'DATA',
        'profiles/updates/1Q-2020': 'DATA',
    }
    FILES = dict.fromkeys(EXPECTED_TYPES, u'')

    def test_get_entry_type_for_path(self):
        p = self.PROFILE()
        for f, expt in self.EXPECTED_TYPES.items():
            self.assertEqual(
                    p.get_entry_type_for_path(f),
                    expt,
                    "type mismatch for {}".format(f))

    def test_update_entries_for_directory(self):
        m = gemato.recursiveloader.ManifestRecursiveLoader(
                os.path.join(self.dir, 'Manifest'),
                hashes=['SHA256', 'SHA512'],
                allow_create=True,
                profile=self.PROFILE())
        m.update_entries_for_directory('')
        for f, expt in self.EXPECTED_TYPES.items():
            self.assertEqual(
                    m.find_path_entry(f).tag,
                    expt,
                    "type mismatch for {}".format(f))
        for f in self.EXPECTED_MANIFESTS:
            self.assertEqual(m.find_path_entry(f).tag, 'MANIFEST',
                    "type mismatch for {}".format(f))
        return m

    def test_set_loader_options(self):
        m = gemato.recursiveloader.ManifestRecursiveLoader(
                os.path.join(self.dir, 'Manifest'),
                profile=self.PROFILE(),
                allow_create=True)
        self.assertIsNotNone(m.hashes)
        self.assertTrue(m.sort)
        self.assertIsNotNone(m.compress_watermark)
        self.assertIsNotNone(m.compress_format)


class BackwardsCompatEbuildRepositoryTests(EbuildRepositoryTests):
    PROFILE = gemato.profile.BackwardsCompatEbuildRepositoryProfile

    def __init__(self, *args, **kwargs):
        self.EXPECTED_TYPES = self.EXPECTED_TYPES.copy()
        self.EXPECTED_TYPES.update({
            'dev-foo/bar/bar-1.ebuild': 'EBUILD',
            'dev-foo/bar/metadata.xml': 'MISC',
            'dev-foo/bar/files/test.patch': 'AUX',
        })
        super(BackwardsCompatEbuildRepositoryTests, self).__init__(
                *args, **kwargs)

    def test_update_entries_for_directory(self):
        m = (super(BackwardsCompatEbuildRepositoryTests, self)
                .test_update_entries_for_directory())
        self.assertEqual(
                m.find_path_entry('dev-foo/bar/files/test.patch').path,
                'files/test.patch')
        self.assertEqual(
                m.find_path_entry('dev-foo/bar/files/test.patch').aux_path,
                'test.patch')