prole/tests/ops/test_k8s.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

35 lines
1.2 KiB
Python

from __future__ import annotations
import subprocess
from pathlib import Path
from unittest.mock import patch
from knoe.ops.context import KnoeContext
from knoe.ops.k8s import apply_yaml, kubectl
def test_kubectl_command_assembly(tmp_path: Path):
ctx = KnoeContext(project_root=tmp_path, env={"FOO": "BAR"})
cp = subprocess.CompletedProcess(args=["kubectl"], returncode=0, stdout="ok\n", stderr="")
with patch("knoe.ops.k8s.check", return_value=cp) as m:
out = kubectl(ctx, "get", "pods", namespace="myns")
assert out == "ok\n"
(cmd,), kwargs = m.call_args
assert cmd[:3] == ["kubectl", "get", "pods"]
assert cmd[-2:] == ["-n", "myns"]
assert kwargs["env"]["FOO"] == "BAR"
def test_apply_yaml_passes_stdin(tmp_path: Path):
ctx = KnoeContext(project_root=tmp_path, env={})
cp = subprocess.CompletedProcess(args=["kubectl"], returncode=0, stdout="", stderr="")
with patch("knoe.ops.k8s.check", return_value=cp) as m:
apply_yaml(ctx, "apiVersion: v1\nkind: Namespace\nmetadata:\n name: x\n")
(cmd,), kwargs = m.call_args
assert cmd[:4] == ["kubectl", "apply", "-f", "-"]
assert "apiVersion" in (kwargs.get("input_text") or "")