feat: implement slice 1 tracer bullet (cli entrypoint, distro detector, and test suite)
This commit is contained in:
commit
63c6cc846b
16 files changed
+1317
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import unittest
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from linux_updater.models import DistroFamily, DistroInfo
|
||||
from linux_updater.core.detector import DistroDetector
|
||||
|
||||
|
||||
class TestDistroDetector(unittest.TestCase):
|
||||
def _create_os_release(self, content: str) -> Path:
|
||||
t = tempfile.NamedTemporaryFile("w", delete=False)
|
||||
t.write(content)
|
||||
t.close()
|
||||
return Path(t.name)
|
||||
|
||||
def test_detect_ubuntu(self):
|
||||
content = """NAME="Ubuntu"
|
||||
VERSION="24.04.1 LTS (Noble Numbat)"
|
||||
ID=ubuntu
|
||||
ID_LIKE=debian
|
||||
PRETTY_NAME="Ubuntu 24.04.1 LTS"
|
||||
VERSION_ID="24.04"
|
||||
"""
|
||||
p = self._create_os_release(content)
|
||||
try:
|
||||
detector = DistroDetector(os_release_path=p)
|
||||
info = detector.detect()
|
||||
self.assertEqual(info.family, DistroFamily.DEBIAN)
|
||||
self.assertEqual(info.distro_id, "ubuntu")
|
||||
self.assertEqual(info.version_id, "24.04")
|
||||
self.assertEqual(info.pretty_name, "Ubuntu 24.04.1 LTS")
|
||||
finally:
|
||||
p.unlink()
|
||||
|
||||
def test_detect_debian(self):
|
||||
content = """PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
|
||||
NAME="Debian GNU/Linux"
|
||||
VERSION_ID="12"
|
||||
VERSION="12 (bookworm)"
|
||||
VERSION_CODENAME=bookworm
|
||||
ID=debian
|
||||
"""
|
||||
p = self._create_os_release(content)
|
||||
try:
|
||||
detector = DistroDetector(os_release_path=p)
|
||||
info = detector.detect()
|
||||
self.assertEqual(info.family, DistroFamily.DEBIAN)
|
||||
self.assertEqual(info.distro_id, "debian")
|
||||
self.assertEqual(info.version_id, "12")
|
||||
finally:
|
||||
p.unlink()
|
||||
|
||||
def test_detect_fedora(self):
|
||||
content = """NAME="Fedora Linux"
|
||||
VERSION="40 (Workstation Edition)"
|
||||
ID=fedora
|
||||
VERSION_ID="40"
|
||||
PRETTY_NAME="Fedora Linux 40 (Workstation Edition)"
|
||||
"""
|
||||
p = self._create_os_release(content)
|
||||
try:
|
||||
detector = DistroDetector(os_release_path=p)
|
||||
info = detector.detect()
|
||||
self.assertEqual(info.family, DistroFamily.RHEL)
|
||||
self.assertEqual(info.distro_id, "fedora")
|
||||
self.assertEqual(info.version_id, "40")
|
||||
finally:
|
||||
p.unlink()
|
||||
|
||||
def test_detect_rocky_rhel_family(self):
|
||||
content = """NAME="Rocky Linux"
|
||||
VERSION="9.4 (Blue Onyx)"
|
||||
ID="rocky"
|
||||
ID_LIKE="rhel centos fedora"
|
||||
VERSION_ID="9.4"
|
||||
PRETTY_NAME="Rocky Linux 9.4 (Blue Onyx)"
|
||||
"""
|
||||
p = self._create_os_release(content)
|
||||
try:
|
||||
detector = DistroDetector(os_release_path=p)
|
||||
info = detector.detect()
|
||||
self.assertEqual(info.family, DistroFamily.RHEL)
|
||||
self.assertEqual(info.distro_id, "rocky")
|
||||
self.assertEqual(info.version_id, "9.4")
|
||||
finally:
|
||||
p.unlink()
|
||||
|
||||
def test_detect_arch(self):
|
||||
content = """NAME="Arch Linux"
|
||||
PRETTY_NAME="Arch Linux"
|
||||
ID=arch
|
||||
BUILD_ID=rolling
|
||||
"""
|
||||
p = self._create_os_release(content)
|
||||
try:
|
||||
detector = DistroDetector(os_release_path=p)
|
||||
info = detector.detect()
|
||||
self.assertEqual(info.family, DistroFamily.ARCH)
|
||||
self.assertEqual(info.distro_id, "arch")
|
||||
self.assertEqual(info.version_id, "rolling")
|
||||
finally:
|
||||
p.unlink()
|
||||
|
||||
def test_detect_missing_os_release(self):
|
||||
non_existent = Path("/tmp/non_existent_os_release_12345")
|
||||
if non_existent.exists():
|
||||
non_existent.unlink()
|
||||
detector = DistroDetector(os_release_path=non_existent)
|
||||
info = detector.detect()
|
||||
self.assertEqual(info.family, DistroFamily.UNKNOWN)
|
||||
self.assertEqual(info.distro_id, "unknown")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user