mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Run sedfile tests in container (#2569)
This commit is contained in:
parent
628e902233
commit
18acd7860b
|
@ -9,18 +9,10 @@
|
||||||
# Is a file change expected? --> use 'sedfile --strict -i'
|
# Is a file change expected? --> use 'sedfile --strict -i'
|
||||||
# Is a file change only on the first container run expected? --> use 'sedfile -i'
|
# Is a file change only on the first container run expected? --> use 'sedfile -i'
|
||||||
|
|
||||||
if [[ -e /usr/local/bin/helpers/log.sh ]]
|
set -ueo pipefail
|
||||||
then
|
|
||||||
# shellcheck source=../scripts/helpers/log.sh
|
# shellcheck source=../scripts/helpers/log.sh
|
||||||
source /usr/local/bin/helpers/log.sh
|
source /usr/local/bin/helpers/log.sh
|
||||||
else
|
|
||||||
# when running BATS (unit tests), this file is not located
|
|
||||||
# inside a container; as a consequence, we need to source
|
|
||||||
# from a different location
|
|
||||||
source target/scripts/helpers/log.sh
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -ueo pipefail
|
|
||||||
|
|
||||||
function __usage { echo "Usage: ${0} -i <replace/delete operation> <file>" ; }
|
function __usage { echo "Usage: ${0} -i <replace/delete operation> <file>" ; }
|
||||||
|
|
||||||
|
|
|
@ -1,71 +1,88 @@
|
||||||
load 'test_helper/common'
|
load 'test_helper/common'
|
||||||
|
|
||||||
|
CONTAINER='sedfile'
|
||||||
|
TEST_FILE='/tmp/sedfile-test.txt'
|
||||||
|
|
||||||
# prepare tests
|
# prepare tests
|
||||||
function setup_file() {
|
function setup_file() {
|
||||||
export CONTAINER_START FILE SEDFILE
|
local PRIVATE_CONFIG
|
||||||
FILE=$(mktemp /tmp/sedfile-test.XXX)
|
PRIVATE_CONFIG="$(duplicate_config_for_container . )"
|
||||||
SEDFILE="/tmp/sedfile"
|
|
||||||
|
|
||||||
# workaround, /CONTAINER_START cannot be used (permission denied)
|
docker run -d --name "${CONTAINER}" \
|
||||||
CONTAINER_START="/tmp/CONTAINER_START"
|
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||||
cp -a "target/bin/sedfile" "${SEDFILE}"
|
-h mail.my-domain.com "${NAME}"
|
||||||
sed -i "s|/CONTAINER_START|${CONTAINER_START}|" "${SEDFILE}"
|
|
||||||
|
|
||||||
|
wait_for_finished_setup_in_container "${CONTAINER}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup() {
|
||||||
# create test file
|
# create test file
|
||||||
echo 'foo bar' > "${FILE}"
|
docker exec "${CONTAINER}" bash -c 'echo "foo bar" > "'"${TEST_FILE}"'"'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking sedfile parameter count" {
|
@test "checking sedfile parameter count" {
|
||||||
run ${SEDFILE}
|
run docker exec "${CONTAINER}" sedfile
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_output --partial 'At least three parameters must be given'
|
assert_output --partial 'At least three parameters must be given'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking sedfile substitute success" {
|
@test "checking sedfile substitute success" {
|
||||||
# change 'bar' to 'baz'
|
# 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_success
|
||||||
assert_output ""
|
assert_output ''
|
||||||
|
|
||||||
# file modified?
|
# file modified?
|
||||||
run test "$(< "${FILE}")" == 'foo baz'
|
run docker exec "${CONTAINER}" cat "${TEST_FILE}"
|
||||||
assert_success
|
assert_success
|
||||||
|
assert_output 'foo baz'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking sedfile substitute failure" {
|
@test "checking sedfile substitute failure (on first container start)" {
|
||||||
run ${SEDFILE} -i 's|bar|baz|' "${FILE}"
|
# 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_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?
|
# file unchanged?
|
||||||
run test "$(< "${FILE}")" == 'foo baz'
|
run docker exec "${CONTAINER}" cat "${TEST_FILE}"
|
||||||
|
assert_success
|
||||||
|
assert_output 'foo bar'
|
||||||
|
|
||||||
|
# recreate marker
|
||||||
|
run docker exec "${CONTAINER}" touch '/CONTAINER_START'
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking sedfile silent failure on substitute" {
|
@test "checking sedfile silent failure on substitute (when DMS was restarted)" {
|
||||||
# create marker to simulate a container restart
|
# try to change 'baz' to 'something' and fail silently
|
||||||
date > "${CONTAINER_START}"
|
run docker exec "${CONTAINER}" sedfile -i 's|baz|something|' "${TEST_FILE}"
|
||||||
|
|
||||||
run ${SEDFILE} -i 's|bar|baz|' "${FILE}"
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output ""
|
assert_output ''
|
||||||
|
|
||||||
# file unchanged?
|
# file unchanged?
|
||||||
run test "$(< "${FILE}")" == 'foo baz'
|
run docker exec "${CONTAINER}" cat "${TEST_FILE}"
|
||||||
assert_success
|
assert_success
|
||||||
|
assert_output 'foo bar'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking sedfile substitude failure (strict)" {
|
@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_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?
|
# file unchanged?
|
||||||
run test "$(< "${FILE}")" == 'foo baz'
|
run docker exec "${CONTAINER}" cat "${TEST_FILE}"
|
||||||
assert_success
|
assert_success
|
||||||
|
assert_output 'foo bar'
|
||||||
}
|
}
|
||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
function teardown_file() {
|
function teardown_file() {
|
||||||
rm -f "${CONTAINER_START}" "${FILE}" "${SEDFILE}"
|
docker rm -f "${CONTAINER}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue