1
0
mirror of https://github.com/tomav/docker-mailserver.git synced 2024-06-27 03:35:23 +02:00
docker-mailserver/test/sedfile.bats

72 lines
1.8 KiB
Plaintext
Raw Normal View History

2022-01-10 01:12:07 +01:00
load 'test_helper/common'
# prepare tests
function setup_file() {
export CONTAINER_START FILE SEDFILE
FILE=$(mktemp /tmp/sedfile-test.XXX)
SEDFILE="/tmp/sedfile"
# workaround, /CONTAINER_START cannot be used (permission denied)
CONTAINER_START="/tmp/CONTAINER_START"
cp -a "target/bin/sedfile" "${SEDFILE}"
sed -i "s|/CONTAINER_START|${CONTAINER_START}|" "${SEDFILE}"
# create test file
echo 'foo bar' > "${FILE}"
}
@test "checking sedfile parameter count" {
run ${SEDFILE}
assert_failure
scripts: refactored scripts located under `target/bin/` (#2500) * refactored scripts located under `target/bin/` The scripts under `target/bin/` now use the new log and I replaced some `""` with `''` on the way. The functionality stays the same, this mostly style and log. * corrected fail2ban (script and tests) * corrected OpenDKIM log output in tests * reverted (some) changes to `sedfile` Moreover, a few messages for BATS were streamlined and a regression in the linting script reverted. * apple PR feedback * improve log output from `fail2ban` script The new output has a single, clear message with the '[ ERROR ] ' prefix, and then output that explains the error afterwards. This is coherent with the logging style which should be used while providing more information than just a single line about IPTables not functioning. * simplified `setquota` script * consistently named the `__usage` function Before, scripts located under `target/bin/` were using `usage` or `__usage`. Now, they're using `__usage` as they should. * improved `sedfile` With `sedfile`, we cannot use the helper functions in a nice way because it is used early in the Dockerfile at a stage where the helper scripts are not yet copied. The script has been adjusted to be canonical with all the other scripts under `target/bin/`. * fixed tests * removed `__usage` from places where it does not belong `__usage` is to be used on wrong user input, not on other failures as well. This was fixed in `delquota` and `setquota`. * apply PR review feedback
2022-03-26 09:30:09 +01:00
assert_output --partial 'Error: At least three parameters must be given'
2022-01-10 01:12:07 +01:00
}
@test "checking sedfile substitute success" {
# change 'bar' to 'baz'
run ${SEDFILE} -i 's|bar|baz|' "${FILE}"
assert_success
assert_output ""
# file modified?
run test "$(< "${FILE}")" == 'foo baz'
assert_success
}
@test "checking sedfile substitute failure" {
run ${SEDFILE} -i 's|bar|baz|' "${FILE}"
assert_failure
scripts: refactored scripts located under `target/bin/` (#2500) * refactored scripts located under `target/bin/` The scripts under `target/bin/` now use the new log and I replaced some `""` with `''` on the way. The functionality stays the same, this mostly style and log. * corrected fail2ban (script and tests) * corrected OpenDKIM log output in tests * reverted (some) changes to `sedfile` Moreover, a few messages for BATS were streamlined and a regression in the linting script reverted. * apple PR feedback * improve log output from `fail2ban` script The new output has a single, clear message with the '[ ERROR ] ' prefix, and then output that explains the error afterwards. This is coherent with the logging style which should be used while providing more information than just a single line about IPTables not functioning. * simplified `setquota` script * consistently named the `__usage` function Before, scripts located under `target/bin/` were using `usage` or `__usage`. Now, they're using `__usage` as they should. * improved `sedfile` With `sedfile`, we cannot use the helper functions in a nice way because it is used early in the Dockerfile at a stage where the helper scripts are not yet copied. The script has been adjusted to be canonical with all the other scripts under `target/bin/`. * fixed tests * removed `__usage` from places where it does not belong `__usage` is to be used on wrong user input, not on other failures as well. This was fixed in `delquota` and `setquota`. * apply PR review feedback
2022-03-26 09:30:09 +01:00
assert_output --partial "Error: No difference after call to 'sed' in 'sedfile' (sed -i s|bar|baz| /tmp/sedfile-test"
2022-01-10 01:12:07 +01:00
# file unchanged?
run test "$(< "${FILE}")" == 'foo baz'
assert_success
}
@test "checking sedfile silent failure on substitute" {
# create marker to simulate a container restart
date > "${CONTAINER_START}"
run ${SEDFILE} -i 's|bar|baz|' "${FILE}"
assert_success
assert_output ""
# file unchanged?
run test "$(< "${FILE}")" == 'foo baz'
assert_success
}
@test "checking sedfile substitude failure (strict)" {
run ${SEDFILE} --strict -i 's|bar|baz|' "${FILE}"
assert_failure
scripts: refactored scripts located under `target/bin/` (#2500) * refactored scripts located under `target/bin/` The scripts under `target/bin/` now use the new log and I replaced some `""` with `''` on the way. The functionality stays the same, this mostly style and log. * corrected fail2ban (script and tests) * corrected OpenDKIM log output in tests * reverted (some) changes to `sedfile` Moreover, a few messages for BATS were streamlined and a regression in the linting script reverted. * apple PR feedback * improve log output from `fail2ban` script The new output has a single, clear message with the '[ ERROR ] ' prefix, and then output that explains the error afterwards. This is coherent with the logging style which should be used while providing more information than just a single line about IPTables not functioning. * simplified `setquota` script * consistently named the `__usage` function Before, scripts located under `target/bin/` were using `usage` or `__usage`. Now, they're using `__usage` as they should. * improved `sedfile` With `sedfile`, we cannot use the helper functions in a nice way because it is used early in the Dockerfile at a stage where the helper scripts are not yet copied. The script has been adjusted to be canonical with all the other scripts under `target/bin/`. * fixed tests * removed `__usage` from places where it does not belong `__usage` is to be used on wrong user input, not on other failures as well. This was fixed in `delquota` and `setquota`. * apply PR review feedback
2022-03-26 09:30:09 +01:00
assert_output --partial "Error: No difference after call to 'sed' in 'sedfile' (sed -i s|bar|baz| /tmp/sedfile-test"
2022-01-10 01:12:07 +01:00
# file unchanged?
run test "$(< "${FILE}")" == 'foo baz'
assert_success
}
# clean up
function teardown_file() {
rm -f "${CONTAINER_START}" "${FILE}" "${SEDFILE}"
}