1
1
Fork 0
mirror of https://github.com/docker-mailserver/docker-mailserver synced 2024-06-01 23:06:05 +02:00

Fix setup/teardown_file to work in full suite run

The previous mechanism would only run them once for the whole suite
This commit is contained in:
Martin Schulze 2019-08-09 01:34:04 +02:00
parent d8956d3b29
commit 85fa5d242f
3 changed files with 35 additions and 13 deletions

View File

@ -1,15 +1,11 @@
load 'test_helper/common'
function setup() {
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then
setup_file
fi
run_setup_file_if_necessary
}
function teardown() {
if [ "$BATS_TEST_NUMBER" -eq ${#BATS_TEST_NAMES[@]} ]; then
teardown_file
fi
run_teardown_file_if_necessary
}
function setup_file() {
@ -31,6 +27,10 @@ function teardown_file() {
docker rm -f mail_with_postgrey
}
@test "first" {
# this test must come first to reliably identify when to run setup_file
}
@test "checking postgrey: /etc/postfix/main.cf correctly edited" {
run docker exec mail_with_postgrey /bin/bash -c "grep 'bl.spamcop.net, check_policy_service inet:127.0.0.1:10023' /etc/postfix/main.cf | wc -l"
assert_success
@ -94,4 +94,8 @@ function teardown_file() {
run docker exec mail_with_postgrey /bin/sh -c "grep -i 'action=pass, reason=recipient whitelist' /var/log/mail/mail.log | wc -l"
assert_success
assert_output 1
}
@test "last" {
# this test is only there to reliably mark the end for the teardown_file
}

View File

@ -1,15 +1,11 @@
load 'test_helper/common'
function setup() {
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then
setup_file
fi
run_setup_file_if_necessary
}
function teardown() {
if [ "$BATS_TEST_NUMBER" -eq ${#BATS_TEST_NAMES[@]} ]; then
teardown_file
fi
run_teardown_file_if_necessary
}
function setup_file() {
@ -31,6 +27,10 @@ function teardown_file() {
docker rm -f mail_with_relays
}
@test "first" {
# this test must come first to reliably identify when to run setup_file
}
@test "checking relay hosts: default mapping is added from env vars" {
run docker exec mail_with_relays /bin/sh -c 'cat /etc/postfix/relayhost_map | grep -e "^@domainone.tld\s\+\[default.relay.com\]:2525" | wc -l | grep 1'
assert_success
@ -54,4 +54,8 @@ function teardown_file() {
@test "checking relay hosts: default auth entry is added" {
run docker exec mail_with_relays /bin/sh -c 'cat /etc/postfix/sasl_passwd | grep -e "^\[default.relay.com\]:2525\s\+smtp_user:smtp_password" | wc -l | grep 1'
assert_success
}
@test "last" {
# this test is only there to reliably mark the end for the teardown_file
}

View File

@ -4,7 +4,7 @@ load 'test_helper/bats-assert/load'
NAME=tvial/docker-mailserver:testing
# default timeout is 60 seconds
TEST_TIMEOUT_IN_SECONDS=${TIMEOUT-60}
TEST_TIMEOUT_IN_SECONDS=${TEST_TIMEOUT_IN_SECONDS-60}
function repeat_until_success_or_timeout {
if ![[ "$1" ~= '^[0-9]+$' ]]; then
@ -32,4 +32,18 @@ function wait_for_smtp_port_in_container() {
# @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'"
}
# use in setup() in conjunction with a `@test "first" {}` to trigger setup_file reliably
function run_setup_file_if_necessary() {
if [ "$BATS_TEST_NAME" == 'test_first' ]; then
setup_file
fi
}
# use in teardown() in conjunction with a `@test "last" {}` to trigger teardown_file reliably
function run_teardown_file_if_necessary() {
if [ "$BATS_TEST_NAME" == 'test_last' ]; then
teardown_file
fi
}