mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +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:
74
test/util/lib.sh
Normal file
74
test/util/lib.sh
Normal file
@@ -0,0 +1,74 @@
|
||||
# Library to write the shell scripts in the tests.
|
||||
|
||||
function init() {
|
||||
if [ "$V" == "1" ]; then
|
||||
set -v
|
||||
fi
|
||||
|
||||
export TBASE="$(realpath `dirname ${0}`)"
|
||||
cd ${TBASE}
|
||||
|
||||
export UTILDIR="$(realpath ${TBASE}/../util/)"
|
||||
|
||||
# Remove the directory where test-mda will deliver mail, so previous
|
||||
# runs don't interfere with this one.
|
||||
rm -rf .mail
|
||||
|
||||
# Set traps to kill our subprocesses when we exit (for any reason).
|
||||
# https://stackoverflow.com/questions/360201/
|
||||
trap "exit" INT TERM
|
||||
trap "kill 0" EXIT
|
||||
}
|
||||
|
||||
function generate_cert() {
|
||||
go run ${UTILDIR}/generate_cert.go "$@"
|
||||
}
|
||||
|
||||
function chasquid() {
|
||||
# HOSTALIASES: so we "fake" hostnames.
|
||||
# PATH: so chasquid can call test-mda without path issues.
|
||||
HOSTALIASES=${TBASE}/hosts \
|
||||
PATH=${UTILDIR}:${PATH} \
|
||||
go run ${TBASE}/../../chasquid.go "$@"
|
||||
}
|
||||
|
||||
function run_msmtp() {
|
||||
# msmtp will check that the rc file is only user readable.
|
||||
chmod 600 msmtprc
|
||||
|
||||
HOSTALIASES=${TBASE}/hosts \
|
||||
msmtp -C msmtprc "$@"
|
||||
}
|
||||
|
||||
function mail_diff() {
|
||||
${UTILDIR}/mail_diff "$@"
|
||||
}
|
||||
|
||||
function success() {
|
||||
echo "SUCCESS"
|
||||
}
|
||||
|
||||
# Wait until there's something listening on the given port.
|
||||
function wait_until_ready() {
|
||||
PORT=$1
|
||||
|
||||
while ! nc -z localhost $PORT; do
|
||||
sleep 0.1
|
||||
done
|
||||
}
|
||||
|
||||
# Wait for the given file to exist.
|
||||
function wait_for_file() {
|
||||
while ! [ -e ${1} ]; do
|
||||
sleep 0.1
|
||||
done
|
||||
}
|
||||
|
||||
# Generate certs for the given domain.
|
||||
function generate_certs_for() {
|
||||
mkdir -p config/domains/${1}
|
||||
(
|
||||
cd config/domains/${1}
|
||||
generate_cert -ca -duration=1h -host=${1}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user