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,55 +1,46 @@
|
|||
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||
|
||||
function setup_file() {
|
||||
local PRIVATE_CONFIG
|
||||
export ALL IPV4 IPV6
|
||||
TEST_NAME_PREFIX='Dovecot protocols:'
|
||||
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container . "${IPV4}")
|
||||
ALL="mail_dovecot_all_protocols"
|
||||
IPV4="mail_dovecot_ipv4"
|
||||
IPV6="mail_dovecot_ipv6"
|
||||
@test "${TEST_NAME_PREFIX} dual-stack IP configuration" {
|
||||
local CONTAINER_NAME='dms-test-dovecot_protocols_all'
|
||||
local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=)
|
||||
|
||||
docker run --rm -d --name "${ALL}" \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-e DOVECOT_INET_PROTOCOLS= \
|
||||
-h mail.my-domain.com \
|
||||
-t "${NAME}"
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
docker run --rm -d --name "${IPV4}" \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-e DOVECOT_INET_PROTOCOLS=ipv4 \
|
||||
-h mail.my-domain.com \
|
||||
-t "${NAME}"
|
||||
|
||||
docker run --rm -d --name "${IPV6}" \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-e DOVECOT_INET_PROTOCOLS=ipv6 \
|
||||
-h mail.my-domain.com \
|
||||
-t "${NAME}"
|
||||
}
|
||||
|
||||
@test 'checking dovecot IP configuration' {
|
||||
wait_for_finished_setup_in_container "${ALL}"
|
||||
run docker exec "${ALL}" grep '^#listen = \*, ::' /etc/dovecot/dovecot.conf
|
||||
_run_in_container grep '^#listen = \*, ::' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
assert_output '#listen = *, ::'
|
||||
|
||||
docker rm -f "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test 'checking dovecot IPv4 configuration' {
|
||||
wait_for_finished_setup_in_container "${IPV4}"
|
||||
run docker exec "${IPV4}" grep '^listen = \*$' /etc/dovecot/dovecot.conf
|
||||
@test "${TEST_NAME_PREFIX} IPv4 configuration" {
|
||||
local CONTAINER_NAME='dms-test-dovecot_protocols_ipv4'
|
||||
local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=ipv4)
|
||||
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
_run_in_container grep '^listen = \*$' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
assert_output 'listen = *'
|
||||
|
||||
docker rm -f "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test 'checking dovecot IPv6 configuration' {
|
||||
wait_for_finished_setup_in_container "${IPV6}"
|
||||
run docker exec "${IPV6}" grep '^listen = \[::\]$' /etc/dovecot/dovecot.conf
|
||||
@test "${TEST_NAME_PREFIX} IPv6 configuration" {
|
||||
local CONTAINER_NAME='dms-test-dovecot_protocols_ipv6'
|
||||
local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=ipv6)
|
||||
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
_run_in_container grep '^listen = \[::\]$' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
assert_output 'listen = [::]'
|
||||
}
|
||||
|
||||
function teardown_file {
|
||||
docker rm -f "${ALL}" "${IPV4}" "${IPV6}"
|
||||
docker rm -f "${CONTAINER_NAME}"
|
||||
}
|
||||
|
|
|
@ -1,31 +1,23 @@
|
|||
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||
|
||||
TEST_NAME_PREFIX='helper functions inside container:'
|
||||
CONTAINER_NAME='dms-test-helper_functions'
|
||||
|
||||
function setup_file() {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
||||
|
||||
docker run -d --name mail_helper_functions \
|
||||
--cap-add=NET_ADMIN \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-e ENABLE_FETCHMAIL=1 \
|
||||
-h mail.my-domain.com -t "${NAME}"
|
||||
|
||||
wait_for_finished_setup_in_container mail_helper_functions
|
||||
init_with_defaults
|
||||
common_container_setup
|
||||
}
|
||||
|
||||
function teardown_file() {
|
||||
docker rm -f mail_helper_functions
|
||||
}
|
||||
|
||||
@test "check helper functions (network.sh): _sanitize_ipv4_to_subnet_cidr" {
|
||||
run docker exec mail_helper_functions bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 255.255.255.255/0"
|
||||
assert_output "0.0.0.0/0"
|
||||
|
||||
run docker exec mail_helper_functions bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/20"
|
||||
assert_output "192.168.240.0/20"
|
||||
|
||||
run docker exec mail_helper_functions bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/32"
|
||||
assert_output "192.168.255.14/32"
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test "${TEST_NAME_PREFIX} _sanitize_ipv4_to_subnet_cidr" {
|
||||
_run_in_container bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 255.255.255.255/0"
|
||||
assert_output "0.0.0.0/0"
|
||||
|
||||
_run_in_container bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/20"
|
||||
assert_output "192.168.240.0/20"
|
||||
|
||||
_run_in_container bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/32"
|
||||
assert_output "192.168.255.14/32"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue