forked from GoogleContainerTools/distroless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_metadata_test.py
50 lines (40 loc) · 2.19 KB
/
parse_metadata_test.py
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
import unittest
import os
from package_manager.parse_metadata import parse_package_metadata
class TestParseMetadata(unittest.TestCase):
def setUp(self):
current_dir = os.path.dirname(__file__)
filename = os.path.join(current_dir, 'testdata', 'Packages.txt')
# parse_package_metadata is called on the binary output of gzip.open
with open(filename, 'rb') as f:
data = f.read()
self.data = data
self.mirror_url = "http://debian.org"
self.package_prefix = "http://dummy/prefix/"
self.debian_repo_metadata = parse_package_metadata(self.data, self.mirror_url, "20170701", "")
self.arbitrary_repo_metadata = parse_package_metadata(self.data, "", "", self.package_prefix)
def test_debian_repo_url_rewrite(self):
""" Relative url should have gotten rewritten with absolute url """
self.assertEqual(
self.debian_repo_metadata["libnewlib-dev"]["Filename"],
self.mirror_url + "/debian/20170701/" + "pool/main/n/newlib/libnewlib-dev_2.1.0+git20140818.1a8323b-2_all.deb")
def test_arbitrary_repo_url_rewrite(self):
""" Relative url should have gotten rewritten with absolute url using the given package prefix """
self.assertEqual(
self.arbitrary_repo_metadata["libnewlib-dev"]["Filename"],
self.package_prefix + "pool/main/n/newlib/libnewlib-dev_2.1.0+git20140818.1a8323b-2_all.deb")
def test_get_all_packages(self):
""" Parser should identify all packages """
expected_packages = ["libnewlib-dev",
"libnewlib-doc",
"newlib-source",
"newmail",
"zzuf",]
for _ in expected_packages:
self.assertEqual(expected_packages.sort(), list(self.debian_repo_metadata.keys()).sort())
def test_multiline_key(self):
""" Multiline keys should be properly parsed """
expected_tags = "interface::commandline, mail::notification, role::program,scope::utility, works-with::mail"
self.assertEqual(expected_tags, self.debian_repo_metadata["newmail"]["Tag"])
if __name__ == '__main__':
unittest.main()