]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
tests: add a small testsuite for mlmmj-maintd
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 26 Oct 2022 12:36:47 +0000 (14:36 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 26 Oct 2022 12:36:47 +0000 (14:36 +0200)
src/mlmmj-maintd.c
tests/Kyuafile.in
tests/Makefile.am
tests/mlmmj-maintd.sh [new file with mode: 0755]

index a4249825672ba51f8f2e398a64c927ae10a278b8..ae99f6a921cbb2314ed2f719150a2699a04b679c 100644 (file)
@@ -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);
index 5daf0698bfa2c22aca9fd0b7b530b7fc2c0268cc..09a165041a6129ac201e63c77ba88ba7e1bd99e3 100644 (file)
@@ -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'}
index 61c46789c6cfeb47eeae143c3fe1fb13c865232c..1e4ea441b2aa92de321c77ecf6b8427a373dce92 100644 (file)
@@ -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 (executable)
index 0000000..90f4dc2
--- /dev/null
@@ -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
+}