prole/tests/installer/test_verify_k3s_services_status.py
chrisfu d397b3000e Fix installer ctx apply flow and registry namespace
- Add explicit Apply button for kubectl context switching to avoid half-applied changes

- Allow kubeconfig/context-based auth without requiring K3S_TOKEN when kubeconfig is valid

- Prompt cleanup/reset of previous Common Core services namespace to prevent resource collisions

- Remove hardcoded 'common-services' registry namespace; default registry deploy/check to SERVICE_NAMESPACE/REGISTRY_NAMESPACE

- Update mocks and add regression tests for namespace resolution and installer behavior
2026-03-07 10:35:27 -08:00

40 lines
1.1 KiB
Python

from pathlib import Path
import sys
import subprocess
# Ensure `installer` is importable when tests are invoked directly via `pytest`
# (the project also provides `tests/run_tests.sh` which sets `PYTHONPATH=.`).
PROJECT_ROOT = Path(__file__).resolve().parents[2]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from installer.core import env as core_env
def test_verify_k3s_services_status_does_not_require_token_when_kubeconfig_available(
monkeypatch, tmp_path
):
kubeconfig = tmp_path / "kubeconfig"
kubeconfig.write_text("dummy")
def fake_run(cmd, capture_output=True, text=True, timeout=None, env=None):
return subprocess.CompletedProcess(
args=cmd,
returncode=0,
stdout="registry\nopenbao\nopentofu\n",
stderr="",
)
monkeypatch.setattr(core_env.subprocess, "run", fake_run)
status = core_env._verify_k3s_services_status(
project_root=PROJECT_ROOT,
managed_kubeconfig=str(kubeconfig),
)
assert status["registry"] == "Good"
assert status["openbao"] == "Good"
assert status["opentofu"] == "Good"