1
0
mirror of https://github.com/tomav/docker-mailserver.git synced 2024-07-16 04:38:13 +02:00
docker-mailserver/test/tests/serial/sedfile.bats

82 lines
2.2 KiB
Plaintext
Raw Normal View History

load "${REPOSITORY_ROOT}/test/helper/setup"
load "${REPOSITORY_ROOT}/test/helper/common"
2022-01-10 01:12:07 +01:00
2022-05-05 12:58:00 +02:00
TEST_FILE='/tmp/sedfile-test.txt'
BATS_TEST_NAME_PREFIX='[sedfile] '
CONTAINER_NAME='dms-test_sedfile'
2022-05-05 12:58:00 +02:00
2022-01-10 01:12:07 +01:00
# prepare tests
function setup_file() {
_init_with_defaults
_common_container_setup
2022-05-05 12:58:00 +02:00
}
2022-01-10 01:12:07 +01:00
function teardown_file() { _default_teardown ; }
2022-05-05 12:58:00 +02:00
function setup() {
2022-01-10 01:12:07 +01:00
# create test file
_run_in_container_bash "echo 'foo bar' >'${TEST_FILE}'"
2022-01-10 01:12:07 +01:00
}
@test 'checking parameter count' {
_run_in_container sedfile
2022-01-10 01:12:07 +01:00
assert_failure
assert_output --partial 'At least three parameters must be given'
2022-01-10 01:12:07 +01:00
}
@test 'checking substitute success' {
2022-01-10 01:12:07 +01:00
# change 'bar' to 'baz'
_run_in_container sedfile -i 's|bar|baz|' "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_success
2022-05-05 12:58:00 +02:00
assert_output ''
2022-01-10 01:12:07 +01:00
# file modified?
_run_in_container cat "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_success
2022-05-05 12:58:00 +02:00
assert_output 'foo baz'
2022-01-10 01:12:07 +01:00
}
@test 'checking sedfile substitute failure (on first container start)' {
2022-05-05 12:58:00 +02:00
# delete marker
_run_in_container rm '/CONTAINER_START'
2022-05-05 12:58:00 +02:00
assert_success
# try to change 'baz' to 'something' and fail
_run_in_container sedfile -i 's|baz|something|' "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_failure
2022-05-05 12:58:00 +02:00
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|baz|something| /tmp/sedfile-test.txt)"
2022-01-10 01:12:07 +01:00
# file unchanged?
_run_in_container cat "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_success
2022-05-05 12:58:00 +02:00
assert_output 'foo bar'
2022-01-10 01:12:07 +01:00
2022-05-05 12:58:00 +02:00
# recreate marker
_run_in_container touch '/CONTAINER_START'
2022-05-05 12:58:00 +02:00
assert_success
}
2022-01-10 01:12:07 +01:00
@test 'checking sedfile silent failure on substitute (when DMS was restarted)' {
2022-05-05 12:58:00 +02:00
# try to change 'baz' to 'something' and fail silently
_run_in_container sedfile -i 's|baz|something|' "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_success
2022-05-05 12:58:00 +02:00
assert_output ''
2022-01-10 01:12:07 +01:00
# file unchanged?
_run_in_container cat "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_success
2022-05-05 12:58:00 +02:00
assert_output 'foo bar'
2022-01-10 01:12:07 +01:00
}
@test 'checking sedfile substitude failure (strict)' {
2022-05-05 12:58:00 +02:00
# try to change 'baz' to 'something' and fail
_run_in_container sedfile --strict -i 's|baz|something|' "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_failure
2022-05-05 12:58:00 +02:00
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|baz|something| /tmp/sedfile-test.txt)"
2022-01-10 01:12:07 +01:00
# file unchanged?
_run_in_container cat "${TEST_FILE}"
2022-01-10 01:12:07 +01:00
assert_success
2022-05-05 12:58:00 +02:00
assert_output 'foo bar'
2022-01-10 01:12:07 +01:00
}