docker-mailserver/test/tests/serial/sedfile.bats

82 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

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