from datetime import UTC, datetime

from worker_watcher.collectors.base import CollectorContext
from worker_watcher.collectors.systemd import SystemdCollector
from worker_watcher.config import CollectorConfig


class FakeRunner:
    def run(self, args, timeout_seconds):
        assert args[0:2] == ["systemctl", "show"]
        return 0, "LoadState=loaded\nActiveState=active\nSubState=running\nResult=success\nExecMainStatus=0\n", ""


def test_systemd_collector_uses_read_only_show(tmp_path) -> None:
    config = CollectorConfig("systemd", "systemd", definitions=({"job_key": "systemd.worker.main", "service_name": "worker.service"},))
    result = SystemdCollector(FakeRunner()).collect(CollectorContext(datetime.now(UTC), "host", config, tmp_path))
    assert result.success
    assert result.observations[0].health_status.value == "healthy"
