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
}