46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
|
|
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
|