mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
{} and uppercase
This commit is contained in:
parent
6bff929b13
commit
0da7ee0c1d
|
@ -21,12 +21,12 @@ function teardown() {
|
|||
}
|
||||
|
||||
function setup_file() {
|
||||
private_config=$(duplicate_config_for_container .)
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
||||
# copy the custom DHE params in local config
|
||||
cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "${private_config}/dhparams.pem"
|
||||
cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "${PRIVATE_CONFIG}/dhparams.pem"
|
||||
|
||||
docker run -d --name mail_manual_dhparams_not_one_dir \
|
||||
-v "${private_config}":/tmp/docker-mailserver \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-e DMS_DEBUG=0 \
|
||||
-e ONE_DIR=0 \
|
||||
|
|
|
@ -9,31 +9,31 @@ function teardown() {
|
|||
}
|
||||
|
||||
function setup_file() {
|
||||
private_config="$(duplicate_config_for_container . mail_lets_domain)"
|
||||
PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_domain)"
|
||||
docker run -d --name mail_lets_domain \
|
||||
-v "${private_config}":/tmp/docker-mailserver \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-v "${private_config}/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \
|
||||
-v "${PRIVATE_CONFIG}/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \
|
||||
-e DMS_DEBUG=0 \
|
||||
-e SSL_TYPE=letsencrypt \
|
||||
-h mail.my-domain.com -t ${NAME}
|
||||
wait_for_finished_setup_in_container mail_lets_domain
|
||||
|
||||
private_config="$(duplicate_config_for_container . mail_lets_hostname)"
|
||||
PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_hostname)"
|
||||
docker run -d --name mail_lets_hostname \
|
||||
-v "${private_config}":/tmp/docker-mailserver \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-v "${private_config}/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \
|
||||
-v "${PRIVATE_CONFIG}/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \
|
||||
-e DMS_DEBUG=0 \
|
||||
-e SSL_TYPE=letsencrypt \
|
||||
-h mail.my-domain.com -t ${NAME}
|
||||
wait_for_finished_setup_in_container mail_lets_hostname
|
||||
|
||||
private_config="$(duplicate_config_for_container . mail_lets_acme_json)"
|
||||
PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_acme_json)"
|
||||
cp "$(private_config_path mail_lets_acme_json)/letsencrypt/acme.json" "$(private_config_path mail_lets_acme_json)/acme.json"
|
||||
docker run -d --name mail_lets_acme_json \
|
||||
-v "${private_config}":/tmp/docker-mailserver \
|
||||
-v "${private_config}/acme.json":/etc/letsencrypt/acme.json:ro \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-v "${PRIVATE_CONFIG}/acme.json":/etc/letsencrypt/acme.json:ro \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-e DMS_DEBUG=0 \
|
||||
-e SSL_TYPE=letsencrypt \
|
||||
|
|
|
@ -5,13 +5,13 @@ load 'test_helper/common'
|
|||
@test "repeat_until_success_or_timeout returns instantly on success" {
|
||||
SECONDS=0
|
||||
repeat_until_success_or_timeout 1 true
|
||||
[[ $SECONDS -le 1 ]]
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
}
|
||||
|
||||
@test "repeat_until_success_or_timeout waits for timeout on persistent failure" {
|
||||
SECONDS=0
|
||||
run repeat_until_success_or_timeout 2 false
|
||||
[[ $SECONDS -ge 2 ]]
|
||||
[[ ${SECONDS} -ge 2 ]]
|
||||
assert_failure
|
||||
assert_output --partial "Timed out on command"
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ load 'test_helper/common'
|
|||
@test "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 ]]
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
assert_failure
|
||||
assert_output --partial "early aborting"
|
||||
}
|
||||
|
@ -38,44 +38,44 @@ load 'test_helper/common'
|
|||
@test "run_until_success_or_timeout returns instantly on success" {
|
||||
SECONDS=0
|
||||
run_until_success_or_timeout 2 true
|
||||
[[ $SECONDS -le 1 ]]
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "run_until_success_or_timeout waits for timeout on persistent failure" {
|
||||
SECONDS=0
|
||||
! run_until_success_or_timeout 2 false
|
||||
[[ $SECONDS -ge 2 ]]
|
||||
[[ ${SECONDS} -ge 2 ]]
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "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 ]]
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
}
|
||||
|
||||
@test "repeat_in_container_until_success_or_timeout run command in container" {
|
||||
local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100)
|
||||
SECONDS=0
|
||||
! repeat_in_container_until_success_or_timeout 10 "$CONTAINER_NAME" sh -c "echo '$CONTAINER_NAME' > /tmp/marker"
|
||||
[[ $SECONDS -le 1 ]]
|
||||
run docker exec "$CONTAINER_NAME" cat /tmp/marker
|
||||
assert_output "$CONTAINER_NAME"
|
||||
! repeat_in_container_until_success_or_timeout 10 "${CONTAINER_NAME}" sh -c "echo '${CONTAINER_NAME}' > /tmp/marker"
|
||||
[[ ${SECONDS} -le 1 ]]
|
||||
run docker exec "${CONTAINER_NAME}" cat /tmp/marker
|
||||
assert_output "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test "container_is_running" {
|
||||
local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100)
|
||||
container_is_running "$CONTAINER_NAME"
|
||||
docker rm -f "$CONTAINER_NAME"
|
||||
! container_is_running "$CONTAINER_NAME"
|
||||
container_is_running "${CONTAINER_NAME}"
|
||||
docker rm -f "${CONTAINER_NAME}"
|
||||
! container_is_running "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test "wait_for_smtp_port_in_container aborts wait after timeout" {
|
||||
local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100)
|
||||
SECONDS=0
|
||||
TEST_TIMEOUT_IN_SECONDS=2 run wait_for_smtp_port_in_container "$CONTAINER_NAME"
|
||||
[[ $SECONDS -ge 2 ]]
|
||||
TEST_TIMEOUT_IN_SECONDS=2 run wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
[[ ${SECONDS} -ge 2 ]]
|
||||
assert_failure
|
||||
assert_output --partial "Timed out on command"
|
||||
}
|
||||
|
@ -83,11 +83,11 @@ load 'test_helper/common'
|
|||
@test "wait_for_smtp_port_in_container returns immediately when port found" {
|
||||
local CONTAINER_NAME=$(docker run --rm -d alpine sh -c "sleep 10")
|
||||
|
||||
docker exec "$CONTAINER_NAME" apk add netcat-openbsd
|
||||
docker exec "$CONTAINER_NAME" nc -l 25 &
|
||||
docker exec "${CONTAINER_NAME}" apk add netcat-openbsd
|
||||
docker exec "${CONTAINER_NAME}" nc -l 25 &
|
||||
|
||||
SECONDS=0
|
||||
TEST_TIMEOUT_IN_SECONDS=5 run wait_for_smtp_port_in_container "$CONTAINER_NAME"
|
||||
[[ $SECONDS -lt 5 ]]
|
||||
TEST_TIMEOUT_IN_SECONDS=5 run wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
[[ ${SECONDS} -lt 5 ]]
|
||||
assert_success
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
load 'test_helper/bats-support/load'
|
||||
load 'test_helper/bats-assert/load'
|
||||
|
||||
NAME=tvial/docker-mailserver:testing
|
||||
# NAME=tvial/docker-mailserver:testing
|
||||
|
||||
# default timeout is 120 seconds
|
||||
TEST_TIMEOUT_IN_SECONDS=${TEST_TIMEOUT_IN_SECONDS-120}
|
||||
|
@ -11,9 +11,9 @@ NUMBER_OF_LOG_LINES=${NUMBER_OF_LOG_LINES-10}
|
|||
# @param --fatal-test <command eval string> additional test whose failure aborts immediately
|
||||
# @param ... test to run
|
||||
function repeat_until_success_or_timeout {
|
||||
local fatal_failure_test_command
|
||||
local FATAL_FAILURE_TEST_COMMAND
|
||||
if [[ "${1}" == "--fatal-test" ]]; then
|
||||
fatal_failure_test_command="${2}"
|
||||
FATAL_FAILURE_TEST_COMMAND="${2}"
|
||||
shift 2
|
||||
fi
|
||||
if ! [[ "${1}" =~ ^[0-9]+$ ]]; then
|
||||
|
@ -25,8 +25,8 @@ function repeat_until_success_or_timeout {
|
|||
shift 1
|
||||
until "${@}"
|
||||
do
|
||||
if [[ -n "${fatal_failure_test_command}" ]] && ! eval "${fatal_failure_test_command}"; then
|
||||
echo "\`${fatal_failure_test_command}\` failed, early aborting repeat_until_success of \`${*}\`" >&2
|
||||
if [[ -n "${FATAL_FAILURE_TEST_COMMAND}" ]] && ! eval "${FATAL_FAILURE_TEST_COMMAND}"; then
|
||||
echo "\`${FATAL_FAILURE_TEST_COMMAND}\` failed, early aborting repeat_until_success of \`${*}\`" >&2
|
||||
return 1
|
||||
fi
|
||||
sleep 1
|
||||
|
@ -75,7 +75,7 @@ function container_is_running() {
|
|||
# @param ${1} port
|
||||
# @param ${2} container name
|
||||
function wait_for_tcp_port_in_container() {
|
||||
repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec ${2} /bin/sh -c "nc -z 0.0.0.0 ${1}"
|
||||
repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec "${2}" /bin/sh -c "nc -z 0.0.0.0 ${1}"
|
||||
}
|
||||
|
||||
# @param ${1} name of the postfix container
|
||||
|
@ -90,13 +90,13 @@ function wait_for_amavis_port_in_container() {
|
|||
|
||||
# @param ${1} name of the postfix container
|
||||
function wait_for_finished_setup_in_container() {
|
||||
local status=0
|
||||
repeat_until_success_or_timeout --fatal-test "container_is_running ${1}" "${TEST_TIMEOUT_IN_SECONDS}" sh -c "docker logs ${1} | grep 'is up and running'" || status=1
|
||||
if [[ ${status} -eq 1 ]]; then
|
||||
local STATUS=0
|
||||
repeat_until_success_or_timeout --fatal-test "container_is_running ${1}" "${TEST_TIMEOUT_IN_SECONDS}" sh -c "docker logs ${1} | grep 'is up and running'" || STATUS=1
|
||||
if [[ ${STATUS} -eq 1 ]]; then
|
||||
echo "Last ${NUMBER_OF_LOG_LINES} lines of container \`${1}\`'s log"
|
||||
docker logs "${1}" | tail -n "${NUMBER_OF_LOG_LINES}"
|
||||
fi
|
||||
return ${status}
|
||||
return ${STATUS}
|
||||
}
|
||||
|
||||
SETUP_FILE_MARKER="${BATS_TMPDIR}/$(basename "${BATS_TEST_FILENAME}").setup_file"
|
||||
|
@ -177,6 +177,8 @@ function wait_for_service() {
|
|||
function wait_for_changes_to_be_detected_in_container() {
|
||||
local CONTAINER_NAME="${1}"
|
||||
local TIMEOUT=${TEST_TIMEOUT_IN_SECONDS}
|
||||
repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" \
|
||||
repeat_in_container_until_success_or_timeout \
|
||||
"${TIMEOUT}" \
|
||||
"${CONTAINER_NAME}" \
|
||||
bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null'
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue