From 72ed000ccf2f4d814d39f29b1cbec03eb8f5defa Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Mon, 18 Feb 2019 07:55:33 -0500 Subject: [PATCH] simple testing framework --- tests/00_minimal.miltertest | 8 ++++++ tests/01_connect.miltertest | 14 ++++++++++ tests/runtests | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/00_minimal.miltertest create mode 100755 tests/01_connect.miltertest create mode 100755 tests/runtests diff --git a/tests/00_minimal.miltertest b/tests/00_minimal.miltertest new file mode 100644 index 0000000..a07b48e --- /dev/null +++ b/tests/00_minimal.miltertest @@ -0,0 +1,8 @@ +-- -*- lua -*- +mt.echo("beginning test") +conn = mt.connect("unix:signing.sock") +if conn == nil then + error "mt.connect() failed" +end +mt.disconnect(conn) +mt.echo("test complete") diff --git a/tests/01_connect.miltertest b/tests/01_connect.miltertest new file mode 100755 index 0000000..bd4c730 --- /dev/null +++ b/tests/01_connect.miltertest @@ -0,0 +1,14 @@ +-- -*- lua -*- +mt.echo("beginning test") +conn = mt.connect("unix:signing.sock") +if conn == nil then + error "mt.connect() failed" +end +if mt.conninfo(conn, "localhost", "127.0.0.1") ~= nil then + error "mt.conninfo() failed" +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error "mt.conninfo() unexpected reply" +end +mt.disconnect(conn) +mt.echo("test complete") diff --git a/tests/runtests b/tests/runtests new file mode 100755 index 0000000..fbfceba --- /dev/null +++ b/tests/runtests @@ -0,0 +1,51 @@ +#!/bin/bash + +set -e +WORKDIR=$(mktemp -d) +TESTDIR=$(realpath "$(dirname "$0")") + +cd "$WORKDIR" + +dknewkey --ktype ed25519 testkey +cat > signing.conf < stderr:\n" + cat stderr + printf -- "-> end stderr\n" + fi + rm -rf "$WORKDIR" +} + +PYTHONPATH="$(dirname "$TESTDIR")" dkimpy-milter signing.conf 2>stderr & +trap cleanup EXIT + +# ugly ugly (how are we supposed to know that the filter is ready?): +sleep 2 + +# uses miltertest from opendkim: +for x in ${TESTS:-"$TESTDIR"/*.miltertest}; do + if ! [ -e "$x" ]; then + if [ -e "$TESTDIR/$x" ]; then + x="$TESTDIR/$x" + fi + fi + printf -- "-> running %s...\n" "$x" + miltertest -s "$x" +done