Refactor command handling

This now supports usage/help texts
This commit is contained in:
2025-05-18 17:56:53 +02:00
parent 26ef9b45d4
commit dcf0b4274c
15 changed files with 337 additions and 431 deletions

View File

@ -1,10 +1,12 @@
"""Test registration."""
import allure
import pytest
from .types import ClientRegistry, CommandRunner, ProcessRunner
@allure.title("Test client registration")
@pytest.mark.enable_registration(True)
@pytest.mark.asyncio
async def test_register_client(
@ -29,8 +31,9 @@ async def test_register_client(
assert found is True
session.stdin.write(public_key)
result = await session.stdout.readline()
assert "OK" in result
data = await session.stdout.read()
assert isinstance(data, str)
assert "Key is valid. Registering client" in data
# Test that we can connect
@ -39,3 +42,28 @@ async def test_register_client(
assert result.stdout is not None
assert isinstance(result.stdout, str)
assert result.stdout.rstrip() == "mocked-secret-testsecret"
@allure.title("Test register command help")
@pytest.mark.enable_registration(True)
@pytest.mark.asyncio
async def test_register_cmd_help(ssh_command_runner: CommandRunner, client_registry: ClientRegistry) -> None:
"""Test running register --help"""
await client_registry["add_client"]("test-client", ["mysecret"])
result = await ssh_command_runner("test-client", "register --help")
assert result.exit_status == 0
print(result.stdout)
assert isinstance(result.stdout, str)
lines = result.stdout.splitlines()
assert lines[0] == "register"
assert len(lines) > 4
# TODO: Test running register with an existing client.