mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-04 10:05:00 +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
|
@ -1,48 +1,36 @@
|
|||
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||
|
||||
# Can run tests in parallel?: No
|
||||
# Shared static container name: TEST_NAME
|
||||
TEST_NAME_PREFIX='spam (Amavis):'
|
||||
CONTAINER_NAME='dms-test-spam_bounced'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env ENABLE_AMAVIS=1
|
||||
--env ENABLE_SPAMASSASSIN=1
|
||||
--env PERMIT_DOCKER=container
|
||||
--env SPAMASSASSIN_SPAM_TO_INBOX=0
|
||||
)
|
||||
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container_to_respond "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
# Test case
|
||||
# ---------
|
||||
# When SPAMASSASSIN_SPAM_TO_INBOX=0, spam messages must be bounced (rejected).
|
||||
# SPAMASSASSIN_SPAM_TO_INBOX=1 is covered in `mail_spam_junk_folder.bats`.
|
||||
# Original test PR: https://github.com/docker-mailserver/docker-mailserver/pull/1485
|
||||
|
||||
function teardown() {
|
||||
docker rm -f "${TEST_NAME}"
|
||||
}
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
}
|
||||
|
||||
# Not used
|
||||
# function teardown_file() {
|
||||
# }
|
||||
|
||||
@test "checking amavis: spam message is bounced (rejected)" {
|
||||
# shellcheck disable=SC2034
|
||||
local TEST_DOCKER_ARGS=(
|
||||
--env ENABLE_SPAMASSASSIN=1
|
||||
--env PERMIT_DOCKER=container
|
||||
--env SPAMASSASSIN_SPAM_TO_INBOX=0
|
||||
)
|
||||
|
||||
common_container_setup 'TEST_DOCKER_ARGS'
|
||||
|
||||
_should_bounce_spam
|
||||
}
|
||||
|
||||
function _should_bounce_spam() {
|
||||
wait_for_smtp_port_in_container_to_respond "${TEST_NAME}"
|
||||
|
||||
@test "${TEST_NAME_PREFIX} spam message is bounced (rejected)" {
|
||||
# send a spam message
|
||||
run docker exec "${TEST_NAME}" /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
||||
_run_in_container /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
||||
assert_success
|
||||
|
||||
# message will be added to a queue with varying delay until amavis receives it
|
||||
run repeat_until_success_or_timeout 60 sh -c "docker logs ${TEST_NAME} | grep 'Blocked SPAM {NoBounceInbound,Quarantined}'"
|
||||
run repeat_until_success_or_timeout 60 sh -c "docker logs ${CONTAINER_NAME} | grep 'Blocked SPAM {NoBounceInbound,Quarantined}'"
|
||||
assert_success
|
||||
}
|
||||
|
|
39
test/tests/parallel/set2/template.bats
Normal file
39
test/tests/parallel/set2/template.bats
Normal file
|
@ -0,0 +1,39 @@
|
|||
# ? load the BATS helper
|
||||
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||
|
||||
# ? global variable initialization
|
||||
# ? to identify the test easily
|
||||
TEST_NAME_PREFIX='template:'
|
||||
# ? must be unique
|
||||
CONTAINER_NAME='dms-test-template'
|
||||
|
||||
# ? test setup
|
||||
|
||||
function setup_file() {
|
||||
# ? optional setup before container is started
|
||||
|
||||
# ? initialize the test helpers
|
||||
init_with_defaults
|
||||
|
||||
# ? add custom arguments supplied to `docker run` here
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env LOG_LEVEL=trace
|
||||
)
|
||||
|
||||
# ? use a helper to correctly setup the container
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
# ? optional setup after the container is started
|
||||
}
|
||||
|
||||
# ? test finalization
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
# ? actual unit tests
|
||||
|
||||
@test "${TEST_NAME_PREFIX} default check" {
|
||||
_run_in_container bash -c "true"
|
||||
assert_success
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue