mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 12:58:04 +00:00
introduce remotelog fixture for capturing systemd-unit logs
This commit is contained in:
@@ -30,11 +30,8 @@ def maildomain():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def chatmail_ssh(maildomain):
|
def sshdomain(maildomain):
|
||||||
domain = os.environ.get("CHATMAIL_SSH")
|
return os.environ.get("CHATMAIL_SSH", maildomain)
|
||||||
if not domain:
|
|
||||||
domain = maildomain
|
|
||||||
return domain
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_report_header():
|
def pytest_report_header():
|
||||||
@@ -51,6 +48,7 @@ def imap(maildomain):
|
|||||||
|
|
||||||
class ImapConn:
|
class ImapConn:
|
||||||
AuthError = imaplib.IMAP4.error
|
AuthError = imaplib.IMAP4.error
|
||||||
|
logunit = "dovecot"
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
self.host = host
|
self.host = host
|
||||||
@@ -71,6 +69,7 @@ def smtp(maildomain):
|
|||||||
|
|
||||||
class SmtpConn:
|
class SmtpConn:
|
||||||
AuthError = smtplib.SMTPAuthenticationError
|
AuthError = smtplib.SMTPAuthenticationError
|
||||||
|
logunit = "postfix"
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
self.host = host
|
self.host = host
|
||||||
@@ -158,13 +157,20 @@ def cmfactory(request, maildomain, gencreds, tmpdir, data):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dovelogreader(chatmail_ssh):
|
def remotelog(sshdomain):
|
||||||
def remote_reader():
|
return RemoteLog(sshdomain)
|
||||||
popen = subprocess.Popen(
|
|
||||||
["ssh", f"root@{chatmail_ssh}", "journalctl -f -u dovecot"],
|
|
||||||
|
class RemoteLog:
|
||||||
|
def __init__(self, sshdomain):
|
||||||
|
self.sshdomain = sshdomain
|
||||||
|
|
||||||
|
def iter(self, unit=""):
|
||||||
|
getjournal = f"journalctl -f -u {unit}" if unit else "journalctl -f"
|
||||||
|
self.popen = subprocess.Popen(
|
||||||
|
["ssh", f"root@{self.sshdomain}", getjournal],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
while 1:
|
while 1:
|
||||||
yield popen.stdout.readline()
|
line = self.popen.stdout.readline()
|
||||||
|
yield line.decode().strip().lower()
|
||||||
return remote_reader
|
|
||||||
|
|||||||
4
online-tests/test_0_basic.py
Normal file
4
online-tests/test_0_basic.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
def test_remotelog(remotelog, imap_or_smtp):
|
||||||
|
lineproducer = remotelog.iter(imap_or_smtp.logunit)
|
||||||
|
imap_or_smtp.connect()
|
||||||
|
assert imap_or_smtp.logunit in next(lineproducer)
|
||||||
@@ -17,7 +17,7 @@ def test_login_basic_functioning(imap_or_smtp, gencreds, lp):
|
|||||||
imap_or_smtp.connect()
|
imap_or_smtp.connect()
|
||||||
lp.sec("success")
|
lp.sec("success")
|
||||||
|
|
||||||
lp.sec("reconnect and verify wrong password fails {user} ")
|
lp.sec(f"reconnect and verify wrong password fails {user} ")
|
||||||
imap_or_smtp.connect()
|
imap_or_smtp.connect()
|
||||||
with pytest.raises(imap_or_smtp.AuthError):
|
with pytest.raises(imap_or_smtp.AuthError):
|
||||||
imap_or_smtp.login(user, password + "wrong")
|
imap_or_smtp.login(user, password + "wrong")
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class TestEndToEndDeltaChat:
|
|||||||
assert msg2.text == "message0"
|
assert msg2.text == "message0"
|
||||||
|
|
||||||
@pytest.mark.slow
|
@pytest.mark.slow
|
||||||
def test_exceed_quota(self, cmfactory, lp, tmpdir, dovelogreader):
|
def test_exceed_quota(self, cmfactory, lp, tmpdir, remotelog):
|
||||||
"""This is a very slow test as it needs to upload >100MB of mail data
|
"""This is a very slow test as it needs to upload >100MB of mail data
|
||||||
before quota is exceeded, and thus depends on the speed of the upload.
|
before quota is exceeded, and thus depends on the speed of the upload.
|
||||||
"""
|
"""
|
||||||
@@ -48,8 +48,7 @@ class TestEndToEndDeltaChat:
|
|||||||
|
|
||||||
addr = ac2.get_config("addr").lower()
|
addr = ac2.get_config("addr").lower()
|
||||||
saved_ok = 0
|
saved_ok = 0
|
||||||
for line in dovelogreader():
|
for line in remotelog.iter("dovecot"):
|
||||||
line = line.decode().lower().strip()
|
|
||||||
if addr not in line:
|
if addr not in line:
|
||||||
# print(line)
|
# print(line)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user