Files
linux-updater/tests/test_packaging.py
T
soda64 0bc914ac8a
Build and Publish Release / Build Packages and Publish (push) Successful in 16s
fix(ci): import build_packages via path in tests and enhance release workflow
2026-10-02 19:51:40 +02:00

70 lines
2.6 KiB
Python

import os
import tarfile
import tempfile
import unittest
from pathlib import Path
import importlib.util
_root_dir = Path(__file__).resolve().parent.parent
_pkg_script = _root_dir / "packaging" / "build_packages.py"
_spec = importlib.util.spec_from_file_location("build_packages", str(_pkg_script))
_module = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_module)
PackageBuilder = _module.PackageBuilder
class TestPackaging(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
self.out_dir = Path(self.temp_dir.name)
self.root_dir = Path(__file__).resolve().parent.parent
self.builder = PackageBuilder(source_root=self.root_dir, output_dir=self.out_dir, version="1.3.0")
def tearDown(self):
self.temp_dir.cleanup()
def test_build_tarball_creates_valid_archive(self):
tar_path = self.builder.build_tarball()
self.assertTrue(tar_path.exists())
self.assertTrue(tar_path.name.endswith(".tar.gz"))
# Verify archive contents
with tarfile.open(str(tar_path), "r:gz") as tar:
names = tar.getnames()
self.assertTrue(any("install.sh" in n for n in names))
self.assertTrue(any("linux_updater/__init__.py" in n for n in names))
self.assertTrue(any("linux-updater.json.example" in n for n in names))
self.assertTrue(any("linux-updater.8" in n for n in names))
def test_build_deb_creates_package_or_tree(self):
deb_path = self.builder.build_deb()
self.assertTrue(deb_path.exists())
self.assertTrue(str(deb_path).endswith(".deb"))
# Check ar header '!<arch>\n'
with open(str(deb_path), "rb") as f:
header = f.read(8)
self.assertEqual(header, b"!<arch>\n")
def test_build_rpm_spec_and_source(self):
rpm_result = self.builder.build_rpm()
self.assertTrue(rpm_result.exists())
spec_path = self.out_dir / "rpm" / "SPECS" / "linux-updater.spec"
self.assertTrue(spec_path.exists())
content = spec_path.read_text(encoding="utf-8")
self.assertIn("Name: linux-updater", content)
self.assertIn("Requires: python3 >= 3.6", content)
self.assertIn("BuildArch: noarch", content)
def test_build_all(self):
results = self.builder.build_all()
self.assertIn("tarball", results)
self.assertIn("deb", results)
self.assertIn("rpm", results)
for k, p in results.items():
self.assertTrue(p.exists(), f"Artifact {k} at {p} does not exist")
if __name__ == "__main__":
unittest.main()