dynamic-infra-tooling/tests/test_cli.py

65 lines
1.8 KiB
Python
Raw Normal View History

2026-02-05 11:33:31 +01:00
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
def test_router_cli(unique_id):
name = f"Test-Cli-{unique_id}"
section = name.lower().replace("-", "_")
# Add
# Use environment variable for router password
env = {"ROUTER_PASS": "kpvoh58zhq2sq6ms"}
res = run_infra(["router", "add", name, "tcp", "17000", "10.32.70.212", "17000"], env=env)
assert res.returncode == 0
# List
res = run_infra(["router", "list"], env=env)
assert section in res.stdout
# Remove
res = run_infra(["router", "remove", section], env=env)
assert res.returncode == 0