From 06b137e5a8bf1c8f5d3ad54f3c73b833382a8271 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 00:02:38 +0200 Subject: [PATCH] Extract container mail_smtponly_without_config into test --- Makefile | 7 ------- test/test_helper/common.bash | 10 ++++++++++ test/tests.bats | 11 ++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 50d2e492..81c61643 100644 --- a/Makefile +++ b/Makefile @@ -54,13 +54,6 @@ run: -e DMS_DEBUG=0 \ -h mail.my-domain.com -t $(NAME) -@ sleep $(SLEEP) - docker run --rm -d --name mail_smtponly_without_config \ - -e SMTP_ONLY=1 \ - -e ENABLE_LDAP=1 \ - -e PERMIT_DOCKER=network \ - -e OVERRIDE_HOSTNAME=mail.mydomain.com \ - -t $(NAME) - -@ sleep $(SLEEP) docker run --rm -d --name mail_override_hostname \ -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index f81de298..f537d95c 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -37,6 +37,16 @@ function repeat_until_success_or_timeout { done } +# @param $1 timeout +# @param $2 container name +# @param ... test command for container +function repeat_in_container_until_success_or_timeout() { + timeout="$1" + container_name="$2" + shift 2 + repeat_until_success_or_timeout "$timeout" --fatal-test "container_is_running $container_name" docker exec "$container_name" "$@" +} + function container_is_running() { [[ "$(docker inspect -f '{{.State.Running}}' "$1")" == "true" ]] } diff --git a/test/tests.bats b/test/tests.bats index e582add6..e52a426e 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -407,7 +407,16 @@ EOF } @test "checking opendkim: /etc/opendkim/KeyTable dummy file generated without keys provided" { - run docker exec mail_smtponly_without_config /bin/bash -c "cat /etc/opendkim/KeyTable" + docker run --rm -d --name mail_smtponly_without_config \ + -e SMTP_ONLY=1 \ + -e ENABLE_LDAP=1 \ + -e PERMIT_DOCKER=network \ + -e OVERRIDE_HOSTNAME=mail.mydomain.com \ + -t ${NAME} + + teardown() { docker rm -f mail_smtponly_without_config; } + + run repeat_in_container_until_success_or_timeout 15 mail_smtponly_without_config /bin/bash -c "cat /etc/opendkim/KeyTable" assert_success }