mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-04 18:15:29 +02:00
tests(refactor): Conversion to parallel tests and use revised helpers
- Introduced `CONTAINER_NAME` and `TEST_NAME_PREFIX` as new vars for better managing test consistency (DRY). - `CONTAINER_NAME` replaces any repeated container name with the variable. The value will differ slightly as the prior prefix (`mail_`) has been changed to `dms-test-`. - `TEST_NAME_PREFIX` provides a prefix value for each `@test` description string. --- chore: Add a reference template for tests
This commit is contained in:
parent
32cc9d30e5
commit
75ee0c1145
7 changed files with 158 additions and 161 deletions
|
@ -3,29 +3,22 @@ load "${REPOSITORY_ROOT}/test/helper/common"
|
|||
|
||||
TEST_NAME_PREFIX='ClamAV:'
|
||||
CONTAINER_NAME='dms-test-clamav'
|
||||
RUN_COMMAND=('run' 'docker' 'exec' "${CONTAINER_NAME}")
|
||||
|
||||
function setup_file() {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container . "${CONTAINER_NAME}")
|
||||
init_with_defaults
|
||||
|
||||
docker run --rm --detach --tty \
|
||||
--name "${CONTAINER_NAME}" \
|
||||
--hostname mail.my-domain.com \
|
||||
--volume "${PRIVATE_CONFIG}:/tmp/docker-mailserver" \
|
||||
--volume "${PWD}/test/test-files:/tmp/docker-mailserver-test:ro" \
|
||||
--env ENABLE_AMAVIS=1 \
|
||||
--env AMAVIS_LOGLEVEL=2 \
|
||||
--env ENABLE_CLAMAV=1 \
|
||||
--env ENABLE_UPDATE_CHECK=0 \
|
||||
--env ENABLE_SPAMASSASSIN=0 \
|
||||
--env ENABLE_FAIL2BAN=0 \
|
||||
--env PERMIT_DOCKER=host \
|
||||
--env CLAMAV_MESSAGE_SIZE_LIMIT=30M \
|
||||
--env LOG_LEVEL=debug \
|
||||
"${IMAGE_NAME}"
|
||||
# Comment for maintainers about `PERMIT_DOCKER=host`:
|
||||
# https://github.com/docker-mailserver/docker-mailserver/pull/2815/files#r991087509
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env ENABLE_CLAMAV=1
|
||||
--env ENABLE_AMAVIS=1
|
||||
--env PERMIT_DOCKER=host
|
||||
--env AMAVIS_LOGLEVEL=2
|
||||
--env CLAMAV_MESSAGE_SIZE_LIMIT=30M
|
||||
--env LOG_LEVEL=trace
|
||||
)
|
||||
|
||||
wait_for_finished_setup_in_container "${CONTAINER_NAME}"
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
# wait for ClamAV to be fully setup or we will get errors on the log
|
||||
repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
|
||||
|
@ -33,48 +26,46 @@ function setup_file() {
|
|||
wait_for_service "${CONTAINER_NAME}" postfix
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
|
||||
"${RUN_COMMAND[@]}" bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
||||
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
||||
assert_success
|
||||
|
||||
wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
function teardown_file() {
|
||||
docker rm -f "${CONTAINER_NAME}"
|
||||
}
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test "${TEST_NAME_PREFIX} process clamd is running" {
|
||||
"${RUN_COMMAND[@]}" bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'"
|
||||
_run_in_container bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} log files exist at /var/log/mail directory" {
|
||||
"${RUN_COMMAND[@]}" bash -c "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail.log'| wc -l"
|
||||
_run_in_container bash -c "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail.log' | wc -l"
|
||||
assert_success
|
||||
assert_output 3
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} should be identified by Amavis" {
|
||||
"${RUN_COMMAND[@]}" grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log
|
||||
_run_in_container grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} freshclam cron is enabled" {
|
||||
"${RUN_COMMAND[@]}" bash -c "grep '/usr/bin/freshclam' -r /etc/cron.d"
|
||||
_run_in_container bash -c "grep '/usr/bin/freshclam' -r /etc/cron.d"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} env CLAMAV_MESSAGE_SIZE_LIMIT is set correctly" {
|
||||
"${RUN_COMMAND[@]}" grep -q '^MaxFileSize 30M$' /etc/clamav/clamd.conf
|
||||
_run_in_container grep -q '^MaxFileSize 30M$' /etc/clamav/clamd.conf
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} rejects virus" {
|
||||
"${RUN_COMMAND[@]}" bash -c "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep '<virus@external.tld> -> <user1@localhost.localdomain>'"
|
||||
_run_in_container bash -c "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep '<virus@external.tld> -> <user1@localhost.localdomain>'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} process clamd restarts when killed" {
|
||||
"${RUN_COMMAND[@]}" bash -c "pkill clamd && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'"
|
||||
_run_in_container bash -c "pkill clamd && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'"
|
||||
assert_success
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue