From: Baptiste Daroussin Date: Wed, 26 Oct 2022 12:36:47 +0000 (+0200) Subject: tests: add a small testsuite for mlmmj-maintd X-Git-Tag: RELEASE_1_4_0a1~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4eaa0c5a57a00fe6d61bc090a1ca4aa4161a7f65;p=thirdparty%2Fmlmmj.git tests: add a small testsuite for mlmmj-maintd --- diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index a4249825..ae99f6a9 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -759,22 +759,22 @@ void do_maintenance(int listfd, const char *listdir, const char *mlmmjsend, dprintf(maintdlogfd, "clean_unsubconf\n"); clean_unsubconf(listfd); - dprintf(maintdlogfd, "resend_queue(%s);\n", mlmmjsend); + dprintf(maintdlogfd, "resend_queue\n"); resend_queue(listfd, mlmmjsend, listdir); - dprintf(maintdlogfd, "resend_requeue(%s);\n", mlmmjsend); + dprintf(maintdlogfd, "resend_requeue\n"); resend_requeue(listfd, mlmmjsend, listdir); dprintf(maintdlogfd, "clean_nolongerbouncing\n"); clean_nolongerbouncing(listfd); - dprintf(maintdlogfd, "unsub_bouncers(%s);\n", mlmmjunsub); + dprintf(maintdlogfd, "unsub_bouncers\n"); unsub_bouncers(listfd, mlmmjunsub, listdir); - dprintf(maintdlogfd, "probe_bouncers(%s);\n", mlmmjbounce); + dprintf(maintdlogfd, "probe_bouncers\n"); probe_bouncers(listfd, mlmmjbounce, listdir); - dprintf(maintdlogfd, "run_digests(%s);\n", mlmmjsend); + dprintf(maintdlogfd, "run_digests\n"); run_digests(listfd, mlmmjsend, listdir); close(maintdlogfd); diff --git a/tests/Kyuafile.in b/tests/Kyuafile.in index 5daf0698..09a16504 100644 --- a/tests/Kyuafile.in +++ b/tests/Kyuafile.in @@ -5,3 +5,4 @@ test_suite('mlmmj') atf_test_program{name='mlmmj'} atf_test_program{name='mlmmj-send'} atf_test_program{name='functional-tests'} +atf_test_program{name='mlmmj-maintd'} diff --git a/tests/Makefile.am b/tests/Makefile.am index 61c46789..1e4ea441 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,7 +13,8 @@ AM_LDFLAGS += -fprofile-instr-generate endif test_scripts = mlmmj-send.sh \ - functional-tests.sh + functional-tests.sh \ + mlmmj-maintd.sh check_SCRIPTS= $(test_scripts:.sh=) SUFFIXES= .sh diff --git a/tests/mlmmj-maintd.sh b/tests/mlmmj-maintd.sh new file mode 100755 index 00000000..90f4dc21 --- /dev/null +++ b/tests/mlmmj-maintd.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/test_env.sh + +tests_init \ + nolongerbouncing \ + discarded \ + basics + +nolongerbouncing_body() +{ + mlmmjmaintd=$(command -v mlmmj-maintd) + mkdir lists + init_ml lists/ml + mkdir -p lists/ml/bounce + + echo test@mlmmjtest > lists/ml/control/listaddress + f1=lists/ml/bounce/msg1 + f2=lists/ml/bounce/msg2 + now=$(date +%s) + now=$((now - 2)) + echo "12" > ${f1}-probe + touch ${f1} + touch ${f1}.lastmsg + echo "$now" > ${f2}-probe + touch ${f2} + touch ${f2}.lastmsg + atf_check -s exit:0 -o empty -e empty $mlmmjmaintd -L lists/ml -F + atf_check -s exit:1 -o empty -e empty test -f $f1 + atf_check -s exit:1 -o empty -e empty test -f $f1-probe + atf_check -s exit:1 -o empty -e empty test -f $f1.lastmsg + atf_check -s exit:0 -o empty -e empty test -f $f2 + atf_check -s exit:0 -o empty -e empty test -f $f2-probe + atf_check -s exit:0 -o empty -e empty test -f $f2.lastmsg +} + +discarded_body() +{ + mlmmjmaintd=$(command -v mlmmj-maintd) + mkdir lists + init_ml lists/ml + + echo test@mlmmjtest > lists/ml/control/listaddress + mkdir -p lists/ml/queue/discarded + f1=lists/ml/queue/discarded/veryold + f2=lists/ml/queue/discarded/notsoold + atf_check touch -t "197001020000" $f1 + atf_check touch $f2 + atf_check -s exit:0 -o empty -e empty $mlmmjmaintd -L lists/ml -F + atf_check -s exit:1 -o empty -e empty test -f $f1 + atf_check -s exit:0 -o empty -e empty test -f $f2 +} + +basics_body() +{ + + mlmmjmaintd=$(command -v mlmmj-maintd) + helptxt="Usage: /usr/home/bapt/dev/mlmmj/tests/../src/mlmmj-maintd [-L | -d] /path/to/dir [-F] + -d: Full path to directory with listdirs + Use this to run maintenance on all list directories + in that directory. + -L: Full path to one list directory + -F: Don't fork, performing one maintenance run only. + This option should be used when one wants to + avoid running another daemon, and use e.g. cron to control it instead. +" + mkdir lists + init_ml lists/ml + + atf_check -s exit:1 -e "inline:mlmmj-maintd: You have to specify -d or -L\n$mlmmjmaintd -h for help\n" $mlmmjmaintd + atf_check -s exit:1 -e "inline:mlmmj-maintd: You have to specify either -d or -L\n$mlmmjmaintd -h for help\n" $mlmmjmaintd -L lists/ml -d . + atf_check -s exit:0 -o "inline:mlmmj-maintd version 1.3.0\n" $mlmmjmaintd -V + atf_check -s exit:0 -o "inline:$helptxt" $mlmmjmaintd -h + echo test@mlmmjtest > lists/ml/control/listaddress + atf_check -s exit:0 -o empty -e empty $mlmmjmaintd -L lists/ml -F + output="Starting maintenance run at + +clean_moderation +clean_discarded +clean_subconf +clean_unsubconf +resend_queue +resend_requeue +clean_nolongerbouncing +unsub_bouncers +probe_bouncers +run_digests +" + atf_check -o "inline:$output" sed -e "s/at .*/at/" lists/ml/mlmmj-maintd.lastrun.log + rm lists/ml/*.log + atf_check -s exit:0 -e ignore $mlmmjmaintd -d lists -F + atf_check -o "inline:$output" sed -e "s/at .*/at/" lists/ml/mlmmj-maintd.lastrun.log +}