1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-19 14:57:04 +00:00
Files
go-chasquid-smtp/test/util/mail_diff
Alberto Bertogli 92a88bd06f 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.
2016-09-12 04:06:56 +01:00

35 lines
674 B
Python
Executable File

#!/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)