prole/tests/installer/test_cfg_save_kubecontext.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

82 lines
2.3 KiB
Python

from __future__ import annotations
from pathlib import Path
from knoe.ui.screens.cfg import ConfigMixin
class _Var:
def __init__(self, value: str):
self._value = value
def get(self) -> str:
return self._value
class _DummyCfgApp(ConfigMixin):
def __init__(self, conf_dir: Path, kubectx: str):
self._conf_dir = conf_dir
self._cfg_path_override = conf_dir / "prole.cfg"
# Minimal surface required by ConfigMixin._save_prole_cfg
self.cluster_env = _Var("dev")
self.selected_kubectx = _Var(kubectx)
self.db_username = _Var("prole-db")
self.db_password = _Var("secret")
self.db_namespace = _Var("knoe-system")
self.db_host_port = _Var("5432")
self.k3s_server_url = _Var("")
self.k3s_token = _Var("")
self.prod_artifacts_path = _Var(str(conf_dir))
self.service_namespace = _Var("knoe-system")
self.prole_cfg_data = {
"Global": {},
"Initialize Cluster": {},
"Dev Cluster (k3d)": {},
"Service Cluster (k3s)": {},
"Prod Cluster (k8s)": {},
}
def _resolve_prole_conf_dir(self) -> Path:
return self._conf_dir
def _deployment_mode(self) -> str:
return "k3d"
def _get_service_namespace(self) -> str:
return "knoe-system"
def _secret_cfg_value(self, _section: str, _key: str, value: str, *_args) -> str:
return value
def _save_ansible_prole_vault(self, _db_password: str):
return None
def _sanitize_sections_for_cfg(self, sections: dict) -> dict:
return sections
def _sync_port_forward_mappings(self):
# Not relevant for this unit test; avoids requiring optional-feature vars.
return None
def _collect_input_snapshot(self) -> dict:
return {}
def test_save_prole_cfg_persists_kubecontext(tmp_path, monkeypatch):
# Avoid touching real env activation during unit test.
import knoe.ui.screens.cfg as cfg_mod
monkeypatch.setattr(cfg_mod.prole_conf, "activate_environment", lambda *_a, **_k: None)
app = _DummyCfgApp(conf_dir=tmp_path, kubectx="k3d-knoe-system")
app._save_prole_cfg()
text = (tmp_path / "prole.cfg").read_text(encoding="utf-8")
assert "KUBECONTEXT" in text
assert "k3d-knoe-system" in text