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
|
@ -1,12 +1,14 @@
|
|||
load "${REPOSITORY_ROOT}/test/test_helper/common"
|
||||
|
||||
@test "repeat_until_success_or_timeout returns instantly on success" {
|
||||
TEST_NAME_PREFIX='test helper functions:'
|
||||
|
||||
@test "${TEST_NAME_PREFIX} repeat_until_success_or_timeout returns instantly on success" {
|
||||
SECONDS=0
|
||||
repeat_until_success_or_timeout 1 true
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
}
|
||||
|
||||
@test "repeat_until_success_or_timeout waits for timeout on persistent failure" {
|
||||
@test "${TEST_NAME_PREFIX} repeat_until_success_or_timeout waits for timeout on persistent failure" {
|
||||
SECONDS=0
|
||||
run repeat_until_success_or_timeout 2 false
|
||||
[[ ${SECONDS} -ge 2 ]]
|
||||
|
@ -14,7 +16,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
assert_output --partial "Timed out on command"
|
||||
}
|
||||
|
||||
@test "repeat_until_success_or_timeout aborts immediately on fatal failure" {
|
||||
@test "${TEST_NAME_PREFIX} repeat_until_success_or_timeout aborts immediately on fatal failure" {
|
||||
SECONDS=0
|
||||
run repeat_until_success_or_timeout --fatal-test false 2 false
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
|
@ -22,7 +24,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
assert_output --partial "early aborting"
|
||||
}
|
||||
|
||||
@test "repeat_until_success_or_timeout expects integer timeout" {
|
||||
@test "${TEST_NAME_PREFIX} repeat_until_success_or_timeout expects integer timeout" {
|
||||
run repeat_until_success_or_timeout 1 true
|
||||
assert_success
|
||||
|
||||
|
@ -33,27 +35,27 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
assert_failure
|
||||
}
|
||||
|
||||
@test "run_until_success_or_timeout returns instantly on success" {
|
||||
@test "${TEST_NAME_PREFIX} run_until_success_or_timeout returns instantly on success" {
|
||||
SECONDS=0
|
||||
run_until_success_or_timeout 2 true
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "run_until_success_or_timeout waits for timeout on persistent failure" {
|
||||
@test "${TEST_NAME_PREFIX} run_until_success_or_timeout waits for timeout on persistent failure" {
|
||||
SECONDS=0
|
||||
! run_until_success_or_timeout 2 false
|
||||
[[ ${SECONDS} -ge 2 ]]
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "repeat_in_container_until_success_or_timeout fails immediately for non-running container" {
|
||||
@test "${TEST_NAME_PREFIX} repeat_in_container_until_success_or_timeout fails immediately for non-running container" {
|
||||
SECONDS=0
|
||||
! repeat_in_container_until_success_or_timeout 10 name-of-non-existing-container true
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
}
|
||||
|
||||
@test "repeat_in_container_until_success_or_timeout run command in container" {
|
||||
@test "${TEST_NAME_PREFIX} repeat_in_container_until_success_or_timeout run command in container" {
|
||||
local CONTAINER_NAME
|
||||
CONTAINER_NAME=$(docker run --rm -d alpine sleep 100)
|
||||
SECONDS=0
|
||||
|
@ -63,7 +65,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
assert_output "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test "container_is_running" {
|
||||
@test "${TEST_NAME_PREFIX} container_is_running" {
|
||||
local CONTAINER_NAME
|
||||
CONTAINER_NAME=$(docker run --rm -d alpine sleep 100)
|
||||
container_is_running "${CONTAINER_NAME}"
|
||||
|
@ -71,7 +73,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
! container_is_running "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test "wait_for_smtp_port_in_container aborts wait after timeout" {
|
||||
@test "${TEST_NAME_PREFIX} wait_for_smtp_port_in_container aborts wait after timeout" {
|
||||
local CONTAINER_NAME
|
||||
CONTAINER_NAME=$(docker run --rm -d alpine sleep 100)
|
||||
SECONDS=0
|
||||
|
@ -82,7 +84,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
}
|
||||
|
||||
# NOTE: Test requires external network access available
|
||||
@test "wait_for_smtp_port_in_container returns immediately when port found" {
|
||||
@test "${TEST_NAME_PREFIX} wait_for_smtp_port_in_container returns immediately when port found" {
|
||||
local CONTAINER_NAME
|
||||
CONTAINER_NAME=$(docker run --rm -d alpine sh -c "sleep 10")
|
||||
|
||||
|
@ -95,7 +97,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
assert_success
|
||||
}
|
||||
|
||||
@test "wait_for_finished_setup_in_container" {
|
||||
@test "${TEST_NAME_PREFIX} wait_for_finished_setup_in_container" {
|
||||
# variable not local to make visible to teardown
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
||||
|
@ -117,7 +119,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
[[ ${SECONDS} -gt 0 ]]
|
||||
}
|
||||
|
||||
@test "duplicate_config_for_container" {
|
||||
@test "${TEST_NAME_PREFIX} duplicate_config_for_container" {
|
||||
local path
|
||||
path=$(duplicate_config_for_container duplicate_config_test)
|
||||
|
||||
|
@ -128,7 +130,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
assert_failure
|
||||
}
|
||||
|
||||
@test "container_has_service_running/wait_for_service" {
|
||||
@test "${TEST_NAME_PREFIX} container_has_service_running/wait_for_service" {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
||||
|
||||
|
@ -156,7 +158,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
assert_failure
|
||||
}
|
||||
|
||||
@test "wait_for_changes_to_be_detected_in_container fails when timeout is reached" {
|
||||
@test "${TEST_NAME_PREFIX} wait_for_changes_to_be_detected_in_container fails when timeout is reached" {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
||||
|
||||
|
@ -182,7 +184,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
! TEST_TIMEOUT_IN_SECONDS=0 wait_for_changes_to_be_detected_in_container "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test "wait_for_changes_to_be_detected_in_container succeeds within timeout" {
|
||||
@test "${TEST_NAME_PREFIX} wait_for_changes_to_be_detected_in_container succeeds within timeout" {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
||||
|
||||
|
@ -208,7 +210,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
}
|
||||
|
||||
# TODO investigate why this test fails
|
||||
@test "wait_for_empty_mail_queue_in_container fails when timeout reached" {
|
||||
@test "${TEST_NAME_PREFIX} wait_for_empty_mail_queue_in_container fails when timeout reached" {
|
||||
skip 'disabled as it fails randomly: https://github.com/docker-mailserver/docker-mailserver/pull/2177'
|
||||
|
||||
local PRIVATE_CONFIG
|
||||
|
@ -240,7 +242,7 @@ load "${REPOSITORY_ROOT}/test/test_helper/common"
|
|||
}
|
||||
|
||||
# TODO investigate why this test fails
|
||||
@test "wait_for_empty_mail_queue_in_container succeeds within timeout" {
|
||||
@test "${TEST_NAME_PREFIX} wait_for_empty_mail_queue_in_container succeeds within timeout" {
|
||||
skip 'disabled as it fails randomly: https://github.com/docker-mailserver/docker-mailserver/pull/2177'
|
||||
|
||||
local PRIVATE_CONFIG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue