Skip to content

Commit 1f14eff

Browse files
committed
tests: make tests work with --ssh-host localhost
1 parent 52f5f18 commit 1f14eff

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

cmdeploy/src/cmdeploy/cmdeploy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def test_cmd_options(parser):
203203
action="store_true",
204204
help="also run slow tests",
205205
)
206+
add_ssh_host_option(parser)
206207

207208

208209
def test_cmd(args, out):
@@ -214,6 +215,9 @@ def test_cmd(args, out):
214215
x = importlib.util.find_spec("deltachat")
215216
if x is None:
216217
out.check_call(f"{sys.executable} -m pip install deltachat")
218+
env = os.environ.copy()
219+
if args.ssh_host:
220+
env["CHATMAIL_SSH"] = args.ssh_host
217221

218222
pytest_path = shutil.which("pytest")
219223
pytest_args = [
@@ -227,7 +231,7 @@ def test_cmd(args, out):
227231
]
228232
if args.slow:
229233
pytest_args.append("--slow")
230-
ret = out.run_ret(pytest_args)
234+
ret = out.run_ret(pytest_args, env=env)
231235
return ret
232236

233237

cmdeploy/src/cmdeploy/tests/online/test_1_basic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
import pytest
88

99
from cmdeploy import remote
10-
from cmdeploy.sshexec import SSHExec
10+
from cmdeploy.cmdeploy import get_sshexec
1111

1212

1313
class TestSSHExecutor:
1414
@pytest.fixture(scope="class")
1515
def sshexec(self, sshdomain):
16-
return SSHExec(sshdomain)
16+
return get_sshexec(sshdomain)
1717

1818
def test_ls(self, sshexec):
19-
out = sshexec(call=remote.rdns.shell, kwargs=dict(command="ls"))
20-
out2 = sshexec(call=remote.rdns.shell, kwargs=dict(command="ls"))
19+
out = sshexec.logged(call=remote.rdns.shell, kwargs=dict(command="ls"))
20+
out2 = sshexec.logged(call=remote.rdns.shell, kwargs=dict(command="ls"))
2121
assert out == out2
2222

2323
def test_perform_initial(self, sshexec, maildomain):
24-
res = sshexec(
24+
res = sshexec.logged(
2525
remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=maildomain)
2626
)
2727
assert res["A"] or res["AAAA"]
@@ -61,7 +61,7 @@ def test_exception(self, sshexec, capsys):
6161
def test_opendkim_restarted(self, sshexec):
6262
"""check that opendkim is not running for longer than a day."""
6363
cmd = "systemctl show opendkim --timestamp=utc --property=ActiveEnterTimestamp"
64-
out = sshexec(call=remote.rshell.shell, kwargs=dict(command=cmd))
64+
out = sshexec.logged(call=remote.rshell.shell, kwargs=dict(command=cmd))
6565
datestring = out.split("=")[1]
6666
since_date = datetime.datetime.strptime(datestring, "%a %Y-%m-%d %H:%M:%S %Z")
6767
now = datetime.datetime.now(since_date.tzinfo)

cmdeploy/src/cmdeploy/tests/plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,13 @@ def __init__(self, sshdomain):
337337

338338
def iter_output(self, logcmd=""):
339339
getjournal = "journalctl -f" if not logcmd else logcmd
340+
print(self.sshdomain)
341+
match self.sshdomain:
342+
case "@local": command = [getjournal]
343+
case "localhost": command = [getjournal]
344+
case _: command = ["ssh", f"root@{self.sshdomain}", getjournal]
340345
self.popen = subprocess.Popen(
341-
["ssh", f"root@{self.sshdomain}", getjournal],
346+
command,
342347
stdout=subprocess.PIPE,
343348
)
344349
while 1:

0 commit comments

Comments
 (0)