prole/tests/installer/test_db_build_registry_status_k3s.py
chrisfu 4ee2b259c9 Checkpoint: rename installer to knoe + harden db build context
- Add build-context helper to copy Docker context safely (ignore runtime data, keep symlinks)

- Update UI and core actions to use ~/.prole/build and shared copy helper

- Add/adjust tests and scripts; introduce knoe ops helpers and update manifests

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-22 01:45:21 -07:00

115 lines
3.5 KiB
Python

from __future__ import annotations
import json
import time
import knoe.ui.screens.database as database_mod
from knoe.ui.screens.database import DatabaseScreenMixin
class _DummyCanvas:
def __init__(self):
self.itemconfig_calls = []
self.itemconfigure_calls = []
def itemconfig(self, item, **kwargs):
self.itemconfig_calls.append((item, dict(kwargs)))
def itemconfigure(self, item, **kwargs):
self.itemconfigure_calls.append((item, dict(kwargs)))
class _ProcResult:
def __init__(self, returncode: int, stdout: str = "", stderr: str = ""):
self.returncode = returncode
self.stdout = stdout
self.stderr = stderr
class _DummyDbScreen(DatabaseScreenMixin):
def __init__(self, *, registry_url: str, prole_cfg_data: dict):
self.prole_cfg_data = prole_cfg_data
self._registry_url = registry_url
self.bg_canvas = _DummyCanvas()
self._db_registry_status_label = 200
self._db_init_registry_button_canvas_window = 100
def safe_after(self, fn, delay: int = 0):
# Execute synchronously for tests.
return fn()
def _cluster_env_key(self):
return "dev"
def ensure_registry_available(self, _env_key: str) -> str:
return self._registry_url
def _registry_namespace(self) -> str:
return "knoe-system"
def _kubectl_base_cmd(self):
return ["kubectl"]
def test_db_build_registry_status_k3s_deployed_does_not_show_not_initialized(monkeypatch):
# If the registry deployment is already ready, the screen must not show
# “(not initialized)” even if the host endpoint is an unusable bind address.
def fake_run(cmd, capture_output, text, timeout):
assert cmd[-6:] == ["deploy", "registry", "-n", "knoe-system", "-o", "json"] or (
cmd[-7:] == ["get", "deploy", "registry", "-n", "knoe-system", "-o", "json"]
)
payload = {"status": {"readyReplicas": 1, "availableReplicas": 1}}
return _ProcResult(0, stdout=json.dumps(payload))
monkeypatch.setattr(database_mod.subprocess, "run", fake_run)
monkeypatch.setattr(database_mod, "_http_ping_registry", lambda *_a, **_k: False)
screen = _DummyDbScreen(
registry_url="0.0.0.0:5000",
prole_cfg_data={"Global": {"DEPLOYMENT_MODE": "k3s"}},
)
screen._ensure_db_build_registry_async()
time.sleep(0.05)
# init button hidden
assert any(
item == 100 and call.get("state") == "hidden"
for item, call in screen.bg_canvas.itemconfigure_calls
)
# status must be “deployed”, not “not initialized”
assert any(
item == 200
and call.get("text") == "Registry: registry.knoe-system.svc.cluster.local:5000 (deployed)"
for item, call in screen.bg_canvas.itemconfig_calls
)
def test_db_build_registry_status_k3s_not_deployed_shows_init(monkeypatch):
def fake_run(_cmd, capture_output, text, timeout):
return _ProcResult(1, stdout="", stderr="not found")
monkeypatch.setattr(database_mod.subprocess, "run", fake_run)
screen = _DummyDbScreen(
registry_url="0.0.0.0:5000",
prole_cfg_data={"Global": {"DEPLOYMENT_MODE": "k3s"}},
)
screen._ensure_db_build_registry_async()
time.sleep(0.05)
assert any(
item == 100 and call.get("state") == "normal"
for item, call in screen.bg_canvas.itemconfigure_calls
)
assert any(
item == 200 and call.get("text") == "Registry: not initialized"
for item, call in screen.bg_canvas.itemconfig_calls
)