Files
home-services/tests/test_composectl.py
T

59 lines
2.0 KiB
Python

import shutil
import unittest
from pathlib import Path
from composectl import (
build_compose_command,
build_update_commands,
detect_runtime,
discover_compose_files,
discover_stack_names,
)
class ComposeCtlTests(unittest.TestCase):
def test_detect_runtime_returns_installed_backend(self):
runtime = detect_runtime(preferred="docker")
expected = "docker" if shutil.which("docker") else "podman"
self.assertEqual(runtime, expected)
def test_build_compose_command_uses_selected_runtime(self):
cmd = build_compose_command(
runtime="podman",
compose_file=Path("media/compose.yaml"),
project_name="media_services",
action="up",
)
self.assertEqual(
cmd,
["podman", "compose", "-f", "media/compose.yaml", "-p", "media_services", "up", "-d"],
)
def test_discover_compose_files_finds_existing_stacks(self):
stack_files = discover_compose_files(Path("."))
self.assertIn(Path("services/media/compose.yaml"), stack_files)
def test_discover_stack_names_returns_inferred_stack_names(self):
stack_names = discover_stack_names(Path("."))
self.assertIn("media", stack_names)
def test_build_update_commands_returns_full_stack_refresh_sequence(self):
commands = build_update_commands(
runtime="podman",
compose_file=Path("services/media/compose.yaml"),
project_name="media_services",
)
self.assertEqual(
commands,
[
["podman", "compose", "-f", "services/media/compose.yaml", "-p", "media_services", "pull"],
["podman", "compose", "-f", "services/media/compose.yaml", "-p", "media_services", "down"],
["podman", "compose", "-f", "services/media/compose.yaml", "-p", "media_services", "up", "-d"],
["podman", "image", "prune", "-f"],
],
)
if __name__ == "__main__":
unittest.main()