tests: Migrate Dovecot DBox tests (sdbox + mdbox) (#3051)

* tests: Migrate Dovecot DBox tests to new testing format
* tests: Group Dovecot related tests into subfolder
This commit is contained in:
Brennan Kinney 2023-02-02 15:30:16 +13:00 committed by GitHub
parent adb30178ae
commit ed6917ff22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 59 deletions

View file

@ -410,8 +410,9 @@ function _count_files_in_directory_in_container()
_run_in_container_bash "[[ -d ${DIRECTORY} ]]"
assert_success
_run_in_container_bash "find ${DIRECTORY} -maxdepth 1 -type f -printf 'x\n'"
_run_in_container_bash "find ${DIRECTORY} -maxdepth 1 -type f"
assert_success
_should_output_number_of_lines "${NUMBER_OF_LINES}"
}

View file

@ -0,0 +1,59 @@
load "${REPOSITORY_ROOT}/test/helper/common"
load "${REPOSITORY_ROOT}/test/helper/setup"
# Feature (ENV DOVECOT_MAILBOX_FORMAT) - Logic in `setup-stack:_setup_dovecot()`
# - Configures mail_location in 10-mail.conf to a supported dbox type
# - Then adds a cron task to purge dbox for freeing disk space (see upstream docs)
# PR: https://github.com/docker-mailserver/docker-mailserver/pull/1314
# Docs (upstream): https://doc.dovecot.org/configuration_manual/mail_location/dbox/#dbox-settings
BATS_TEST_NAME_PREFIX='[Dovecot] '
CONTAINER1_NAME='dms-test_dovecot-dbox_sdbox'
CONTAINER2_NAME='dms-test_dovecot-dbox_mdbox'
function teardown() { _default_teardown ; }
@test "(ENV DOVECOT_MAILBOX_FORMAT=sdbox) should store received mail at expected location" {
export CONTAINER_NAME=${CONTAINER1_NAME}
local CUSTOM_SETUP_ARGUMENTS=(
--env DOVECOT_MAILBOX_FORMAT=sdbox
--env PERMIT_DOCKER=container
)
_init_with_defaults
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
_wait_for_smtp_port_in_container
_send_email 'existing-user1'
_wait_for_empty_mail_queue_in_container
# Mail received should be stored as `u.1` (one file per message)
local MAILBOX_STORAGE='/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails'
_count_files_in_directory_in_container "${MAILBOX_STORAGE}" 3
assert_output --partial "${MAILBOX_STORAGE}/dovecot.index.log"
assert_output --partial "${MAILBOX_STORAGE}/u.1"
assert_output --partial "${MAILBOX_STORAGE}/dovecot.index.cache"
}
@test "(ENV DOVECOT_MAILBOX_FORMAT=mdbox) should store received mail at expected location" {
export CONTAINER_NAME=${CONTAINER2_NAME}
local CUSTOM_SETUP_ARGUMENTS=(
--env DOVECOT_MAILBOX_FORMAT=mdbox
--env PERMIT_DOCKER=container
)
_init_with_defaults
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
_wait_for_smtp_port_in_container
_send_email 'existing-user1'
_wait_for_empty_mail_queue_in_container
# Mail received should be stored in `m.1` (1 or more messages)
local MAILBOX_STORAGE='/var/mail/localhost.localdomain/user1/storage'
_count_files_in_directory_in_container "${MAILBOX_STORAGE}" 2
assert_output --partial "${MAILBOX_STORAGE}/dovecot.map.index.log"
assert_output --partial "${MAILBOX_STORAGE}/m.1"
}

View file

@ -1,29 +0,0 @@
load "${REPOSITORY_ROOT}/test/test_helper/common"
setup_file() {
local PRIVATE_CONFIG
PRIVATE_CONFIG=$(duplicate_config_for_container .)
docker run -d --name mail_with_mdbox_format \
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
-e ENABLE_CLAMAV=0 \
-e ENABLE_SPAMASSASSIN=0 \
-e DOVECOT_MAILBOX_FORMAT=mdbox \
-e PERMIT_DOCKER=host \
-h mail.my-domain.com -t "${NAME}"
wait_for_smtp_port_in_container mail_with_mdbox_format
}
teardown_file() {
docker rm -f mail_with_mdbox_format
}
@test "checking dovecot mailbox format: mdbox file created" {
run docker exec mail_with_mdbox_format /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
assert_success
# shellcheck disable=SC2016
repeat_until_success_or_timeout 30 docker exec mail_with_mdbox_format /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/storage/m.1 | wc -l) -eq 1 ]'
}

View file

@ -1,29 +0,0 @@
load "${REPOSITORY_ROOT}/test/test_helper/common"
setup_file() {
local PRIVATE_CONFIG
PRIVATE_CONFIG=$(duplicate_config_for_container .)
docker run -d --name mail_with_sdbox_format \
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
-e ENABLE_CLAMAV=0 \
-e ENABLE_SPAMASSASSIN=0 \
-e DOVECOT_MAILBOX_FORMAT=sdbox \
-e PERMIT_DOCKER=host \
-h mail.my-domain.com -t "${NAME}"
wait_for_smtp_port_in_container mail_with_sdbox_format
}
teardown_file() {
docker rm -f mail_with_sdbox_format
}
@test "checking dovecot mailbox format: sdbox file created" {
run docker exec mail_with_sdbox_format /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
assert_success
# shellcheck disable=SC2016
repeat_until_success_or_timeout 30 docker exec mail_with_sdbox_format /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1 | wc -l) -eq 1 ]'
}