From a7d97227d393e7d9b5a8fd5a6419ed8114a9caaa Mon Sep 17 00:00:00 2001 From: Fredrick Amnehagen Date: Thu, 5 Feb 2026 11:33:31 +0100 Subject: [PATCH] add tests and config --- config.yaml | 22 ++++++++++++++++++++++ tests/test_cli.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 config.yaml create mode 100644 tests/test_cli.py diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..6d1d32b --- /dev/null +++ b/config.yaml @@ -0,0 +1,22 @@ +# LoopAware Infra CLI Configuration + +# Proxmox/DNS Management +proxmox: + host: "10.32.2.1" + user: "root" + dnsmasq_lxc_id: "11209" + ssh_key: "~/.ssh/id_ed25519_no_pass" + +# Ingress Management (HAProxy) +haproxy: + host: "10.32.1.20" + user: "root" + ssh_key: "~/.ssh/id_ed25519_no_pass" + config_dir: "/etc/haproxy/conf.d" + dynamic_dir: "/etc/haproxy/dynamic" + +# Router Management (OpenWrt) +router: + host: "10.32.0.1" + user: "root" + ssh_key: "~/.ssh/id_ed25519_no_pass" diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..2319748 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,45 @@ +import pytest +import subprocess +import os +import uuid + +# Use the bin/infra wrapper for testing +CLI_BIN = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "bin", "infra")) +CONFIG_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "config.yaml")) + +def run_infra(cmd, env=None): + full_cmd = [CLI_BIN, "--config", CONFIG_PATH] + cmd + return subprocess.run(full_cmd, capture_output=True, text=True, env=env) + +@pytest.fixture +def unique_id(): + return str(uuid.uuid4())[:8] + +def test_dns_cli(unique_id): + mac = f"aa:bb:cc:dd:ee:{unique_id[:2]}" + ip = "10.32.70.210" + hostname = f"test-cli-{unique_id}" + + # Add + res = run_infra(["dns", "add-host", mac, ip, hostname]) + assert res.returncode == 0 + + # List + res = run_infra(["dns", "list"]) + assert mac in res.stdout + + # Remove + res = run_infra(["dns", "remove-host", mac]) + assert res.returncode == 0 + +def test_ingress_cli(unique_id): + domain = f"test-cli-{unique_id}.loopaware.com" + ip = "10.32.70.211" + + # Add + res = run_infra(["ingress", "add", domain, ip, "80"]) + assert res.returncode == 0 + + # Remove + res = run_infra(["ingress", "remove", domain]) + assert res.returncode == 0