Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
86
tests/test_cli.py
Normal file
86
tests/test_cli.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from tai.cli import app
|
||||
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
|
||||
Reference in New Issue
Block a user