From d05255cb0499c70e56ba23bc376e6bed0dcf3e88 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 8 Oct 2019 21:45:05 +0200 Subject: [PATCH] Tests: Extract mail_fetchmail into own .bats file --- Makefile | 8 ----- test/mail_fetchmail.bats | 64 ++++++++++++++++++++++++++++++++++++++++ test/tests.bats | 24 --------------- 3 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 test/mail_fetchmail.bats diff --git a/Makefile b/Makefile index 16ccfb9e..ad7e2361 100644 --- a/Makefile +++ b/Makefile @@ -129,14 +129,6 @@ run: --cap-add=NET_ADMIN \ -h mail.my-domain.com -t $(NAME) sleep 15 - docker run --rm -d --name mail_fetchmail \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_FETCHMAIL=1 \ - --cap-add=NET_ADMIN \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t $(NAME) - sleep 15 docker run --rm -d --name mail_disabled_clamav_spamassassin \ -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ diff --git a/test/mail_fetchmail.bats b/test/mail_fetchmail.bats new file mode 100644 index 00000000..bb6d4d8b --- /dev/null +++ b/test/mail_fetchmail.bats @@ -0,0 +1,64 @@ +load 'test_helper/common' + +function setup() { + run_setup_file_if_necessary +} + +function teardown() { + run_teardown_file_if_necessary +} + +function setup_file() { + docker run -d --name mail_fetchmail \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_FETCHMAIL=1 \ + --cap-add=NET_ADMIN \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME} + wait_for_finished_setup_in_container mail_fetchmail +} + +function teardown_file() { + docker rm -f mail_fetchmail +} + +@test "first" { + skip 'this test must come first to reliably identify when to run setup_file' +} + +# +# processes +# + +@test "checking process: fetchmail (fetchmail server enabled)" { + run docker exec mail_fetchmail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/fetchmail'" + assert_success +} + +# +# fetchmail +# + +@test "checking fetchmail: gerneral options in fetchmailrc are loaded" { + run docker exec mail_fetchmail grep 'set syslog' /etc/fetchmailrc + assert_success +} + +@test "checking fetchmail: fetchmail.cf is loaded" { + run docker exec mail_fetchmail grep 'pop3.example.com' /etc/fetchmailrc + assert_success +} + +# +# supervisor +# + +@test "checking restart of process: fetchmail" { + run docker exec mail_fetchmail /bin/bash -c "pkill fetchmail && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/bin/fetchmail'" + assert_success +} + +@test "last" { + skip 'this test is only there to reliably mark the end for the teardown_file' +} \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index 0487baf6..f7ac2922 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -119,11 +119,6 @@ function count_processed_changes() { assert_failure } -@test "checking process: fetchmail (fetchmail server enabled)" { - run docker exec mail_fetchmail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/fetchmail'" - assert_success -} - @test "checking process: clamav (clamav disabled by ENABLED_CLAMAV=0)" { run docker exec mail_disabled_clamav_spamassassin /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'" assert_failure @@ -840,20 +835,6 @@ function count_processed_changes() { assert_failure } -# -# fetchmail -# - -@test "checking fetchmail: gerneral options in fetchmailrc are loaded" { - run docker exec mail_fetchmail grep 'set syslog' /etc/fetchmailrc - assert_success -} - -@test "checking fetchmail: fetchmail.cf is loaded" { - run docker exec mail_fetchmail grep 'pop3.example.com' /etc/fetchmailrc - assert_success -} - # # system # @@ -1482,11 +1463,6 @@ function count_processed_changes() { assert_success } -@test "checking restart of process: fetchmail" { - run docker exec mail_fetchmail /bin/bash -c "pkill fetchmail && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/bin/fetchmail'" - assert_success -} - @test "checking restart of process: clamav (clamav disabled by ENABLED_CLAMAV=0)" { run docker exec mail_disabled_clamav_spamassassin /bin/bash -c "pkill -f clamd && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'" assert_failure