You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ErrorDetecting/backend/tests/test_ssh_probe.py

28 lines
970 B

import pytest
from app.services.ssh_probe import check_ssh_connectivity
from app.ssh_utils import SSHClient
class _DummyCli:
def __init__(self, host, user, pwd):
self.closed = False
def execute_command_with_timeout(self, cmd, timeout):
return ("ok", "")
def close(self):
self.closed = True
def test_check_ssh_connectivity_success(monkeypatch):
monkeypatch.setattr("app.services.ssh_probe.SSHClient", lambda h,u,p: _DummyCli(h,u,p))
ok, err = check_ssh_connectivity("127.0.0.1", "u", "p", timeout=1)
assert ok is True
assert err is None
class _FailCli:
def __init__(self, host, user, pwd):
raise RuntimeError("connect_failed")
def test_check_ssh_connectivity_fail(monkeypatch):
monkeypatch.setattr("app.services.ssh_probe.SSHClient", lambda h,u,p: _FailCli(h,u,p))
ok, err = check_ssh_connectivity("127.0.0.1", "u", "p", timeout=1)
assert ok is False
assert "connect_failed" in str(err)