mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Extract default relay host test
centralize common test variables and functions
This commit is contained in:
parent
6a7608fe7b
commit
db160bd977
12
Makefile
12
Makefile
|
@ -244,15 +244,6 @@ run:
|
|||
-e DMS_DEBUG=0 \
|
||||
-h mail.my-domain.com -t $(NAME)
|
||||
sleep 15
|
||||
docker run -d --name mail_with_default_relay \
|
||||
-v "`pwd`/test/config/relay-hosts":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \
|
||||
--cap-add=SYS_PTRACE \
|
||||
-e PERMIT_DOCKER=host \
|
||||
-e DMS_DEBUG=0 \
|
||||
-h mail.my-domain.com -t $(NAME)
|
||||
sleep 15
|
||||
|
||||
generate-accounts-after-run:
|
||||
docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
|
||||
|
@ -328,8 +319,7 @@ clean:
|
|||
mail_override_hostname \
|
||||
mail_domainname \
|
||||
mail_srs_domainname \
|
||||
mail_with_relays \
|
||||
mail_with_default_relay
|
||||
mail_with_relays
|
||||
|
||||
@if [ -d config.bak ]; then\
|
||||
rm -rf config ;\
|
||||
|
|
26
test/default_relay_host.bats
Normal file
26
test/default_relay_host.bats
Normal file
|
@ -0,0 +1,26 @@
|
|||
load 'test_helper/common'
|
||||
|
||||
function setup() {
|
||||
docker run -d --name mail_with_default_relay \
|
||||
-v "`pwd`/test/config/relay-hosts":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \
|
||||
--cap-add=SYS_PTRACE \
|
||||
-e PERMIT_DOCKER=host \
|
||||
-e DMS_DEBUG=0 \
|
||||
-h mail.my-domain.com -t ${NAME}
|
||||
wait_for_finished_setup_in_container mail_with_default_relay
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
docker rm -f mail_with_default_relay
|
||||
}
|
||||
|
||||
#
|
||||
# default relay host
|
||||
#
|
||||
|
||||
@test "checking default relay host: default relay host is added to main.cf" {
|
||||
run docker exec mail_with_default_relay /bin/sh -c 'grep -e "^relayhost = default.relay.host.invalid:25" /etc/postfix/main.cf | wc -l | grep 1'
|
||||
assert_success
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
load 'test_helper/bats-support/load'
|
||||
load 'test_helper/bats-assert/load'
|
||||
load 'test_helper/common'
|
||||
|
||||
NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME=non-default-docker-mail-network
|
||||
NAME=tvial/docker-mailserver:testing
|
||||
setup() {
|
||||
docker network create --driver bridge ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}
|
||||
docker network create --driver bridge ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}2
|
||||
|
@ -31,7 +29,7 @@ setup() {
|
|||
-t ${NAME}
|
||||
|
||||
# wait until postfix is up
|
||||
repeat_until_success_or_timeout 60 docker exec mail_smtponly_second_network /bin/sh -c "nc -z 0.0.0.0 25"
|
||||
wait_for_smtp_port_in_container mail_smtponly_second_network
|
||||
}
|
||||
|
||||
teardown() {
|
||||
|
@ -41,20 +39,6 @@ teardown() {
|
|||
docker network rm ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME} ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}2
|
||||
}
|
||||
|
||||
function repeat_until_success_or_timeout {
|
||||
TIMEOUT=$1
|
||||
STARTTIME=$SECONDS
|
||||
shift 1
|
||||
until "$@"
|
||||
do
|
||||
sleep 5
|
||||
if [[ $(($SECONDS - $STARTTIME )) -gt $TIMEOUT ]]; then
|
||||
echo "Timed out on command: $@"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@test "checking PERMIT_DOCKER: connected-networks" {
|
||||
ipnet1=$(docker network inspect --format '{{(index .IPAM.Config 0).Subnet}}' non-default-docker-mail-network)
|
||||
ipnet2=$(docker network inspect --format '{{(index .IPAM.Config 0).Subnet}}' non-default-docker-mail-network2)
|
||||
|
|
35
test/test_helper/common.bash
Normal file
35
test/test_helper/common.bash
Normal file
|
@ -0,0 +1,35 @@
|
|||
load 'test_helper/bats-support/load'
|
||||
load 'test_helper/bats-assert/load'
|
||||
|
||||
NAME=tvial/docker-mailserver:testing
|
||||
|
||||
# default timeout is 60 seconds
|
||||
TEST_TIMEOUT_IN_SECONDS=${TIMEOUT-60}
|
||||
|
||||
function repeat_until_success_or_timeout {
|
||||
if ![[ "$1" ~= '^[0-9]+$' ]]; then
|
||||
echo "First parameter for timeout must be an integer, recieved \"$1\""
|
||||
exit 1
|
||||
fi
|
||||
TIMEOUT=$1
|
||||
STARTTIME=$SECONDS
|
||||
shift 1
|
||||
until "$@"
|
||||
do
|
||||
sleep 5
|
||||
if [[ $(($SECONDS - $STARTTIME )) -gt $TIMEOUT ]]; then
|
||||
echo "Timed out on command: $@"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# @param $1 name of the postfix container
|
||||
function wait_for_smtp_port_in_container() {
|
||||
repeat_until_success_or_timeout $TEST_TIMEOUT_IN_SECONDS docker exec $1 /bin/sh -c "nc -z 0.0.0.0 25"
|
||||
}
|
||||
|
||||
# @param $1 name of the postfix container
|
||||
function wait_for_finished_setup_in_container() {
|
||||
repeat_until_success_or_timeout $TEST_TIMEOUT_IN_SECONDS sh -c "docker logs $1 | grep 'Starting mail server'"
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
load 'test_helper/bats-support/load'
|
||||
load 'test_helper/bats-assert/load'
|
||||
|
||||
|
||||
|
||||
#
|
||||
|
@ -1816,14 +1815,7 @@ function count_processed_changes() {
|
|||
assert_success
|
||||
}
|
||||
|
||||
#
|
||||
# default relay host
|
||||
#
|
||||
|
||||
@test "checking default relay host: default relay host is added to main.cf" {
|
||||
run docker exec mail_with_default_relay /bin/sh -c 'grep -e "^relayhost = default.relay.host.invalid:25" /etc/postfix/main.cf | wc -l | grep 1'
|
||||
assert_success
|
||||
}
|
||||
|
||||
#
|
||||
# relay hosts
|
||||
|
|
Loading…
Reference in a new issue