git » chasquid » commit c4c330d

test: Verify mailbox delivery in minor dialogs test

author Alberto Bertogli
2023-12-23 13:18:36 UTC
committer Alberto Bertogli
2023-12-23 13:21:27 UTC
parent 0c02bfbe768d2d2f31d316f66ae8961243eb525a

test: Verify mailbox delivery in minor dialogs test

The minor dialogs test covers some very specific SMTP exchanges, and
some of those include delivering email.

Today, we don't verify the final mailbox, we just check the SMTP
exchange. However, it can be very useful for some of the tests to do
end-to-end checking of the final mailbox.

This patch implements that ability in the test itself, and on the
(currently only) email delivering dialog.

Subsequent patches that introduce new tests will make use of this
feature.

test/t-12-minor_dialogs/run.sh +22 -1
test/t-12-minor_dialogs/sendmail.cmy.verify +6 -0

diff --git a/test/t-12-minor_dialogs/run.sh b/test/t-12-minor_dialogs/run.sh
index e15277b..8b82683 100755
--- a/test/t-12-minor_dialogs/run.sh
+++ b/test/t-12-minor_dialogs/run.sh
@@ -8,7 +8,7 @@ init
 generate_certs_for testserver
 add_user user@testserver secretpassword
 
-mkdir -p .logs
+mkdir -p .logs .mbox
 chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config &
 wait_until_ready 1025
 
@@ -16,7 +16,28 @@ FAILED=0
 for i in *.cmy; do
 	if ! chamuyero "$i" > ".logs/$i.log" 2>&1 ; then
 		echo "test $i failed, see .logs/$i.log"
+		echo
+		echo "last lines of the log:"
+		tail -n 10 ".logs/$i.log" | sed 's/^/  /g'
+		echo
 		FAILED=1
+		continue
+	fi
+
+	# Some tests do email delivery, this allows us to verify the results.
+	if [ -f "$i.verify" ]; then
+		wait_for_file .mail/user@testserver
+		cp .mail/user@testserver ".mbox/$i.mbox"
+		if ! mail_diff "$i.verify" .mail/user@testserver \
+			> ".mbox/$i.diff" ;
+		then
+			echo "test $i failed, because it had a mail diff"
+			echo
+			echo "mail diff:"
+			sed 's/^/  /g' ".mbox/$i.diff"
+			echo
+			FAILED=1
+		fi
 	fi
 done
 
diff --git a/test/t-12-minor_dialogs/sendmail.cmy.verify b/test/t-12-minor_dialogs/sendmail.cmy.verify
new file mode 100644
index 0000000..633441e
--- /dev/null
+++ b/test/t-12-minor_dialogs/sendmail.cmy.verify
@@ -0,0 +1,6 @@
+From: Mailer daemon <somewhere@horns.com>
+Subject: I've come to haunt you
+
+Muahahahaha
+
+