2022-11-25 22:37:58 +00:00
|
|
|
load "${REPOSITORY_ROOT}/test/test_helper/common"
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
CONTAINER='sedfile'
|
|
|
|
TEST_FILE='/tmp/sedfile-test.txt'
|
|
|
|
|
2022-01-10 00:12:07 +00:00
|
|
|
# prepare tests
|
|
|
|
function setup_file() {
|
2022-05-05 10:58:00 +00:00
|
|
|
local PRIVATE_CONFIG
|
|
|
|
PRIVATE_CONFIG="$(duplicate_config_for_container . )"
|
|
|
|
|
|
|
|
docker run -d --name "${CONTAINER}" \
|
2022-05-30 00:53:30 +00:00
|
|
|
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
|
|
|
-h mail.my-domain.com "${NAME}"
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
wait_for_finished_setup_in_container "${CONTAINER}"
|
|
|
|
}
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
function setup() {
|
2022-01-10 00:12:07 +00:00
|
|
|
# create test file
|
2022-05-05 10:58:00 +00:00
|
|
|
docker exec "${CONTAINER}" bash -c 'echo "foo bar" > "'"${TEST_FILE}"'"'
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking sedfile parameter count" {
|
2022-05-05 10:58:00 +00:00
|
|
|
run docker exec "${CONTAINER}" sedfile
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_failure
|
2022-04-02 13:52:30 +00:00
|
|
|
assert_output --partial 'At least three parameters must be given'
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking sedfile substitute success" {
|
|
|
|
# change 'bar' to 'baz'
|
2022-05-05 10:58:00 +00:00
|
|
|
run docker exec "${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?
|
2022-05-05 10:58:00 +00:00
|
|
|
run docker exec "${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
|
|
|
}
|
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
@test "checking sedfile substitute failure (on first container start)" {
|
|
|
|
# delete marker
|
|
|
|
run docker exec "${CONTAINER}" rm '/CONTAINER_START'
|
|
|
|
assert_success
|
|
|
|
|
|
|
|
# try to change 'baz' to 'something' and fail
|
|
|
|
run docker exec "${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?
|
2022-05-05 10:58:00 +00:00
|
|
|
run docker exec "${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 docker exec "${CONTAINER}" touch '/CONTAINER_START'
|
|
|
|
assert_success
|
|
|
|
}
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
@test "checking sedfile silent failure on substitute (when DMS was restarted)" {
|
|
|
|
# try to change 'baz' to 'something' and fail silently
|
|
|
|
run docker exec "${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?
|
2022-05-05 10:58:00 +00:00
|
|
|
run docker exec "${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 docker exec "${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?
|
2022-05-05 10:58:00 +00:00
|
|
|
run docker exec "${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
|
|
|
}
|
|
|
|
|
|
|
|
# clean up
|
|
|
|
function teardown_file() {
|
2022-05-05 10:58:00 +00:00
|
|
|
docker rm -f "${CONTAINER}"
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|