mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-21 15:17:01 +00:00
test: Add a new local end-to-end test
This patch introduces a new directory, test/, which contains a simple local end-to-end test which runs a chasquid binary and uses msmtp to send an email, which is delivered locally. As it's the first one, it adds a bunch of common infrastructure to simplify writing these kinds of tests. More end-to-end tests will follow, and it's expected that the common infrastructure will also change significantly to accomodate their needs.
This commit is contained in:
34
test/util/mail_diff
Executable file
34
test/util/mail_diff
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import difflib
|
||||
import email.parser
|
||||
import mailbox
|
||||
import sys
|
||||
|
||||
f1, f2 = sys.argv[1:3]
|
||||
|
||||
expected = email.parser.Parser().parse(open(f1))
|
||||
|
||||
mbox = mailbox.mbox(f2, create=False)
|
||||
msg = mbox[0]
|
||||
|
||||
diff = False
|
||||
|
||||
for h, val in expected.items():
|
||||
if h not in msg:
|
||||
print("Header missing: %r" % h)
|
||||
diff = True
|
||||
continue
|
||||
if msg[h] != val:
|
||||
print("Header %r differs: %r != %r" % (h, val, msg[h]))
|
||||
diff = True
|
||||
|
||||
if expected.get_payload() != msg.get_payload():
|
||||
diff = True
|
||||
exp = expected.get_payload().splitlines()
|
||||
got = msg.get_payload().splitlines()
|
||||
print("Payload differs:")
|
||||
for l in difflib.ndiff(exp, got):
|
||||
print(l)
|
||||
|
||||
sys.exit(0 if not diff else 1)
|
||||
Reference in New Issue
Block a user