Files
linux-updater/tests/test_packaging.py
T
soda64 8921c2da13
Build and Publish Release / Build Packages and Publish (push) Failing after 52s
feat(ci): add Gitea Actions release workflow and bump version to 1.3.0
2026-10-02 19:48:20 +02:00

64 lines
2.3 KiB
Python

import os
import tarfile
import tempfile
import unittest
from pathlib import Path
from packaging.build_packages import 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()