88 lines
3.7 KiB
Python
88 lines
3.7 KiB
Python
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Validate package recipes, dependency declarations and source references."""
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from urllib.parse import urlsplit
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "tools/lib"))
|
|
import project as p # noqa: E402 - Load tools/lib after configuring its import path.
|
|
|
|
|
|
class ProjectChecks(unittest.TestCase):
|
|
def test_all_recipes_match_accepted_source(self):
|
|
p.check(list(p.packages()), baseline=True)
|
|
|
|
def test_graph_includes_every_project_once(self):
|
|
modules = p.order(p.packages())
|
|
self.assertEqual(len(modules), len(p.packages()))
|
|
seen = set()
|
|
edges = p.graph()
|
|
for module in modules:
|
|
self.assertTrue(set(edges[module]) <= seen)
|
|
seen.add(module)
|
|
|
|
def test_source_artifact_names_and_repository_urls(self):
|
|
cache_entries = {}
|
|
for entry in p.packages().values():
|
|
originals = [
|
|
artifact
|
|
for artifact in entry["files"]
|
|
if artifact["role"] == "original"
|
|
]
|
|
self.assertEqual(
|
|
len(originals), 0 if entry["format"] == "3.0 (native)" else 1
|
|
)
|
|
for artifact in entry["files"]:
|
|
identity = (artifact["sha256"], artifact["size"])
|
|
self.assertEqual(
|
|
cache_entries.setdefault(artifact["name"], identity), identity
|
|
)
|
|
self.assertEqual(Path(artifact["name"]).name, artifact["name"])
|
|
url = urlsplit(artifact["url"])
|
|
self.assertEqual(url.scheme, "https")
|
|
self.assertTrue(url.hostname)
|
|
publication = urlsplit(p.read(ROOT / "config/release.json")["url"])
|
|
self.assertNotEqual(url.hostname, publication.hostname)
|
|
self.assertRegex(artifact["sha256"], r"^[0-9a-f]{64}$")
|
|
self.assertGreater(artifact["size"], 0)
|
|
self.assertIn(
|
|
artifact["role"],
|
|
{"original", "original-component", "crate", "bootstrap"},
|
|
)
|
|
|
|
def test_release_configuration_matches_environment_files(self):
|
|
release = p.read(ROOT / "config/release.json")
|
|
snapshot = release["snapshot"]
|
|
distro = release["distribution"]
|
|
arch = release["architecture"]
|
|
suite = release["build_suite"]
|
|
sources = (ROOT / "config/debian.sources").read_text()
|
|
self.assertIn(f"/{snapshot}/", sources)
|
|
self.assertIn(f"Suites: {distro} {distro}-updates", sources)
|
|
self.assertIn(f"Suites: {distro}-security", sources)
|
|
for index in p.read(ROOT / "config/snapshot-indexes.json"):
|
|
self.assertIn(f"/{snapshot}/dists/{index['suite']}/InRelease", index["url"])
|
|
bootstrap = (ROOT / "tools/lib/bootstrap-controller").read_text()
|
|
self.assertIn(f"--arch={arch}", bootstrap)
|
|
self.assertIn(
|
|
f'{distro} "$root" https://snapshot.debian.org/archive/debian/{snapshot}/',
|
|
bootstrap,
|
|
)
|
|
configure = (ROOT / "tools/lib/configure-controller").read_text()
|
|
self.assertIn(f"{distro}-{arch}.tar", configure)
|
|
self.assertIn(f"Codename: {suite}\nSuite: {suite}", configure)
|
|
sbuild_conf = (ROOT / "tools/lib/sbuild.conf").read_text()
|
|
self.assertIn(f"$distribution = '{distro}';", sbuild_conf)
|
|
self.assertIn(f"$chroot = '/work/chroots/{distro}-{arch}.tar';", sbuild_conf)
|
|
self.assertIn(
|
|
f"deb [trusted=yes] file:/plasma-next-repository {suite} main",
|
|
sbuild_conf,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|