All checks were successful
CI / test (push) Successful in 15s
Co-authored-by: Copilot <copilot@github.com>
137 lines
3.7 KiB
Python
137 lines
3.7 KiB
Python
from typer.testing import CliRunner
|
|
|
|
from tai.cli import app
|
|
from tai.collectors import CollectedItem, CollectionReport
|
|
from tai.ssh_client import SSHCommandResult
|
|
|
|
|
|
def test_run_command_prints_scaffold_summary() -> None:
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"apache failed",
|
|
"--host",
|
|
"web01",
|
|
"--port",
|
|
"5566",
|
|
"--no-probe",
|
|
"--path",
|
|
"/etc/apache2",
|
|
"--jump-host",
|
|
"bastion01",
|
|
"--ignore-ssh-config",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
assert "tai scaffold ready" in result.stdout
|
|
assert "host=web01" in result.stdout
|
|
assert "port=5566" in result.stdout
|
|
|
|
|
|
def test_probe_success_prints_remote_output_by_default(monkeypatch) -> None: # type: ignore[no-untyped-def]
|
|
async def fake_probe(self) -> SSHCommandResult: # type: ignore[no-untyped-def]
|
|
return SSHCommandResult(
|
|
command="uname -a",
|
|
exit_code=0,
|
|
stdout="Linux ssh 6.12.0",
|
|
stderr="",
|
|
)
|
|
|
|
monkeypatch.setattr("tai.cli.SSHClient.probe", fake_probe)
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"apache failed",
|
|
"--host",
|
|
"ssh.archflux.net",
|
|
"--port",
|
|
"5566",
|
|
"--probe",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
assert "Probe succeeded" in result.stdout
|
|
assert "Linux ssh 6.12.0" in result.stdout
|
|
|
|
|
|
def test_probe_failure_returns_non_zero(monkeypatch) -> None: # type: ignore[no-untyped-def]
|
|
async def fake_probe(self) -> SSHCommandResult: # type: ignore[no-untyped-def]
|
|
return SSHCommandResult(
|
|
command="uname -a",
|
|
exit_code=255,
|
|
stdout="",
|
|
stderr="Permission denied (publickey,password).",
|
|
)
|
|
|
|
monkeypatch.setattr("tai.cli.SSHClient.probe", fake_probe)
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"apache failed",
|
|
"--host",
|
|
"ssh.archflux.net",
|
|
"--port",
|
|
"5566",
|
|
"--probe",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 1
|
|
assert "Probe failed" in result.stdout
|
|
|
|
|
|
def test_collect_success_prints_summary(monkeypatch) -> None: # type: ignore[no-untyped-def]
|
|
async def fake_collect_from_plan(_client, _plan) -> CollectionReport: # type: ignore[no-untyped-def]
|
|
return CollectionReport(
|
|
host="ssh.archflux.net",
|
|
items=[
|
|
CollectedItem(
|
|
name="kernel",
|
|
result=SSHCommandResult(
|
|
command="uname -a",
|
|
exit_code=0,
|
|
stdout="Linux test",
|
|
stderr="",
|
|
),
|
|
),
|
|
CollectedItem(
|
|
name="journal",
|
|
result=SSHCommandResult(
|
|
command="journalctl -n 200",
|
|
exit_code=0,
|
|
stdout="...",
|
|
stderr="",
|
|
stdout_truncated=True,
|
|
),
|
|
),
|
|
],
|
|
)
|
|
|
|
monkeypatch.setattr("tai.cli.collect_from_plan", fake_collect_from_plan)
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"apache failed",
|
|
"--host",
|
|
"ssh.archflux.net",
|
|
"--port",
|
|
"5566",
|
|
"--no-probe",
|
|
"--collect",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
assert "Collection complete" in result.stdout
|
|
assert "kernel: ok" in result.stdout
|
|
assert "journal: ok (truncated)" in result.stdout
|