taler-deployment

Deployment scripts and configuration files
Log | Files | Refs | README

test_buildscript_generic.py (2187B)


      1 #!/usr/bin/env python3
      2 # This file is in the public domain.
      3 
      4 import importlib.machinery
      5 import importlib.util
      6 import tempfile
      7 import unittest
      8 from pathlib import Path
      9 
     10 SCRIPT_PATH = Path(__file__).parents[1] / "buildscripts" / "generic"
     11 LOADER = importlib.machinery.SourceFileLoader("buildscript_generic", str(SCRIPT_PATH))
     12 SPEC = importlib.util.spec_from_loader(LOADER.name, LOADER)
     13 GENERIC = importlib.util.module_from_spec(SPEC)
     14 LOADER.exec_module(GENERIC)
     15 
     16 
     17 class RemoveStalePackagesTests(unittest.TestCase):
     18     def test_removes_only_unreferenced_package_artifacts(self):
     19         with tempfile.TemporaryDirectory() as tmp:
     20             pkgdir = Path(tmp)
     21             current = {
     22                 "component_2.0_amd64.deb",
     23                 "component-dbgsym_2.0_amd64.ddeb",
     24                 "other_1.0_arm64.deb",
     25             }
     26             (pkgdir / "component@amd64.built.current").write_text(
     27                 "component_2.0_amd64.deb\n" "component-dbgsym_2.0_amd64.ddeb\n"
     28             )
     29             (pkgdir / "other@arm64.built.current").write_text("other_1.0_arm64.deb\n")
     30 
     31             stale = {
     32                 "component_1.0_amd64.deb",
     33                 "component-dbgsym_1.0_amd64.ddeb",
     34                 "orphan_0.1_all.deb",
     35             }
     36             for name in current | stale:
     37                 (pkgdir / name).touch()
     38             (pkgdir / "Packages.xz").touch()
     39             (pkgdir / "build.changes").touch()
     40 
     41             GENERIC.remove_stale_packages(pkgdir)
     42 
     43             self.assertTrue(all((pkgdir / name).exists() for name in current))
     44             self.assertTrue(all(not (pkgdir / name).exists() for name in stale))
     45             self.assertTrue((pkgdir / "Packages.xz").exists())
     46             self.assertTrue((pkgdir / "build.changes").exists())
     47 
     48     def test_removes_all_packages_when_no_manifest_references_them(self):
     49         with tempfile.TemporaryDirectory() as tmp:
     50             pkgdir = Path(tmp)
     51             (pkgdir / "orphan_1.0_all.deb").touch()
     52             (pkgdir / "orphan-dbgsym_1.0_all.ddeb").touch()
     53 
     54             GENERIC.remove_stale_packages(pkgdir)
     55 
     56             self.assertEqual([], list(pkgdir.iterdir()))
     57 
     58 
     59 if __name__ == "__main__":
     60     unittest.main()