-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run sedfile tests in container (#2569)
- Loading branch information
1 parent
628e902
commit 18acd78
Showing
2 changed files
with
47 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,88 @@ | ||
load 'test_helper/common' | ||
|
||
CONTAINER='sedfile' | ||
TEST_FILE='/tmp/sedfile-test.txt' | ||
|
||
# prepare tests | ||
function setup_file() { | ||
export CONTAINER_START FILE SEDFILE | ||
FILE=$(mktemp /tmp/sedfile-test.XXX) | ||
SEDFILE="/tmp/sedfile" | ||
local PRIVATE_CONFIG | ||
PRIVATE_CONFIG="$(duplicate_config_for_container . )" | ||
|
||
docker run -d --name "${CONTAINER}" \ | ||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ | ||
-h mail.my-domain.com "${NAME}" | ||
|
||
# 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}" | ||
wait_for_finished_setup_in_container "${CONTAINER}" | ||
} | ||
|
||
function setup() { | ||
# create test file | ||
echo 'foo bar' > "${FILE}" | ||
docker exec "${CONTAINER}" bash -c 'echo "foo bar" > "'"${TEST_FILE}"'"' | ||
} | ||
|
||
@test "checking sedfile parameter count" { | ||
run ${SEDFILE} | ||
run docker exec "${CONTAINER}" sedfile | ||
assert_failure | ||
assert_output --partial 'At least three parameters must be given' | ||
} | ||
|
||
@test "checking sedfile substitute success" { | ||
# change 'bar' to 'baz' | ||
run ${SEDFILE} -i 's|bar|baz|' "${FILE}" | ||
run docker exec "${CONTAINER}" sedfile -i 's|bar|baz|' "${TEST_FILE}" | ||
assert_success | ||
assert_output "" | ||
assert_output '' | ||
|
||
# file modified? | ||
run test "$(< "${FILE}")" == 'foo baz' | ||
run docker exec "${CONTAINER}" cat "${TEST_FILE}" | ||
assert_success | ||
assert_output 'foo baz' | ||
} | ||
|
||
@test "checking sedfile substitute failure" { | ||
run ${SEDFILE} -i 's|bar|baz|' "${FILE}" | ||
@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}" | ||
assert_failure | ||
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|bar|baz| /tmp/sedfile-test" | ||
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|baz|something| /tmp/sedfile-test.txt)" | ||
|
||
# file unchanged? | ||
run test "$(< "${FILE}")" == 'foo baz' | ||
run docker exec "${CONTAINER}" cat "${TEST_FILE}" | ||
assert_success | ||
} | ||
assert_output 'foo bar' | ||
|
||
@test "checking sedfile silent failure on substitute" { | ||
# create marker to simulate a container restart | ||
date > "${CONTAINER_START}" | ||
# recreate marker | ||
run docker exec "${CONTAINER}" touch '/CONTAINER_START' | ||
assert_success | ||
} | ||
|
||
run ${SEDFILE} -i 's|bar|baz|' "${FILE}" | ||
@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}" | ||
assert_success | ||
assert_output "" | ||
assert_output '' | ||
|
||
# file unchanged? | ||
run test "$(< "${FILE}")" == 'foo baz' | ||
run docker exec "${CONTAINER}" cat "${TEST_FILE}" | ||
assert_success | ||
assert_output 'foo bar' | ||
} | ||
|
||
@test "checking sedfile substitude failure (strict)" { | ||
run ${SEDFILE} --strict -i 's|bar|baz|' "${FILE}" | ||
# try to change 'baz' to 'something' and fail | ||
run docker exec "${CONTAINER}" sedfile --strict -i 's|baz|something|' "${TEST_FILE}" | ||
assert_failure | ||
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|bar|baz| /tmp/sedfile-test" | ||
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|baz|something| /tmp/sedfile-test.txt)" | ||
|
||
# file unchanged? | ||
run test "$(< "${FILE}")" == 'foo baz' | ||
run docker exec "${CONTAINER}" cat "${TEST_FILE}" | ||
assert_success | ||
assert_output 'foo bar' | ||
} | ||
|
||
# clean up | ||
function teardown_file() { | ||
rm -f "${CONTAINER_START}" "${FILE}" "${SEDFILE}" | ||
docker rm -f "${CONTAINER}" | ||
} |