mirror of
https://github.com/bokysan/docker-postfix.git
synced 2024-09-20 06:46:10 +08:00
Fix: Fix unit tests
This commit is contained in:
parent
1d74829eaa
commit
4b2f48157b
|
@ -3,36 +3,35 @@
|
|||
load /code/scripts/common.sh
|
||||
load /code/scripts/common-run.sh
|
||||
|
||||
declare temporary_file
|
||||
setup() {
|
||||
temporary_file="$(mktemp -t)"
|
||||
cp /etc/postfix/main.cf "${temporary_file}"
|
||||
}
|
||||
|
||||
@test "verify reading and writting propreties" {
|
||||
teardown() {
|
||||
cat "${temporary_file}" > /etc/postfix/main.cf
|
||||
rm -rf "${temporary_file}"
|
||||
}
|
||||
|
||||
@test "verify reading empty property" {
|
||||
local value
|
||||
local old_value
|
||||
old_value="$(get_postconf "mydestination")"
|
||||
|
||||
do_postconf -# mydestination
|
||||
do_postconf -e "mydestination="
|
||||
|
||||
value="$(get_postconf "mydestination")"
|
||||
if [[ -n "${value}" ]]; then
|
||||
echo "Expected '', got: '$value' for 'mydestination'" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "verify reading full property" {
|
||||
do_postconf -e 'mydestination=$myhostname, localhost.$mydomain $mydomain'
|
||||
|
||||
value="$(get_postconf "mydestination")"
|
||||
if [[ "${value}" != 'mydestination=$myhostname, localhost.$mydomain $mydomain' ]]; then
|
||||
echo "Expected 'mydestination=\$myhostname, localhost.\$mydomain \$mydomain', got: '$value' for mydestination" >&2
|
||||
if [[ "${value}" != '$myhostname, localhost.$mydomain $mydomain' ]]; then
|
||||
echo "Expected '\$myhostname, localhost.\$mydomain \$mydomain', got: '$value' for mydestination" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
do_postconf -# mydestination
|
||||
echo " mydestination = localhost" >> /etc/postfix/main.cf
|
||||
|
||||
value="$(get_postconf "mydestination")"
|
||||
if [[ "${value}" != "localhost" ]]; then
|
||||
echo "Expected 'localhost', got: '$value' for mydestination" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
do_postconf -e "mydestination=${old_value}"
|
||||
}
|
||||
|
|
|
@ -3,66 +3,33 @@
|
|||
load /code/scripts/common.sh
|
||||
load /code/scripts/common-run.sh
|
||||
|
||||
declare temporary_file
|
||||
declare dir_debian="/usr/lib/postfix/sbin"
|
||||
declare dir_alpine="/usr/libexec/postfix"
|
||||
declare dir_temp
|
||||
|
||||
@test "verify reading of daemon_directory" {
|
||||
local daemon_directory
|
||||
local old_daemon_directory
|
||||
local dir_debian="/usr/lib/postfix/sbin"
|
||||
local dir_alpine="/usr/libexec/postfix"
|
||||
local dir_temp="/tmp/deamon_directory"
|
||||
old_daemon_directory="$(get_postconf "daemon_directory")"
|
||||
|
||||
setup() {
|
||||
temporary_file="$(mktemp -t)"
|
||||
dir_temp="$(mktemp -d)"
|
||||
mkdir -p "${dir_temp}"
|
||||
cp /etc/postfix/main.cf "${temporary_file}"
|
||||
|
||||
rm -rf "${dir_debian}.bak" "${dir_alpine}.bak"
|
||||
if [[ -d "${dir_debian}" ]]; then
|
||||
cp -r ${dir_debian} ${dir_temp}
|
||||
mv ${dir_debian} ${dir_debian}.bak
|
||||
cp -r "${dir_debian}" "${dir_temp}/postfix"
|
||||
mv "${dir_debian}" "${dir_debian}.bak"
|
||||
fi
|
||||
|
||||
if [[ -d "${dir_alpine}" ]]; then
|
||||
cp -r ${dir_alpine} ${dir_temp}
|
||||
mv ${dir_alpine} ${dir_alpine}.bak
|
||||
cp -r "${dir_alpine}" "${dir_temp}/postfix"
|
||||
mv "${dir_alpine}" "${dir_alpine}.bak"
|
||||
fi
|
||||
|
||||
# Test if Debian/Ubuntu directory remains the same when run on Debian/Ubuntu
|
||||
cp -r ${dir_temp} ${dir_debian}
|
||||
do_postconf -e "daemon_directory=${dir_debian}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf ${dir_debian} ${dir_alpine}
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_debian}" ]
|
||||
}
|
||||
|
||||
# Test if Debian/Ubuntu directory gets changes the same when run on Alpine
|
||||
cp -r ${dir_temp} ${dir_alpine}
|
||||
do_postconf -e "daemon_directory=${dir_debian}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf ${dir_debian} ${dir_alpine}
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_alpine}" ]
|
||||
|
||||
# Test if Alpine directory remains the same when run on Alpine
|
||||
cp -r ${dir_temp} ${dir_alpine}
|
||||
do_postconf -e "daemon_directory=${dir_alpine}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf ${dir_debian} ${dir_alpine}
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_alpine}" ]
|
||||
|
||||
# Test if Alpine directory gets changes the same when run on Debian/Ubuntu
|
||||
cp -r ${dir_temp} ${dir_debian}
|
||||
do_postconf -e "daemon_directory=${dir_alpine}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf ${dir_debian} ${dir_alpine}
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_debian}" ]
|
||||
|
||||
# Test if things work with custom directory
|
||||
do_postconf -e "daemon_directory=${dir_temp}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf ${dir_debian} ${dir_alpine}
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_temp}" ]
|
||||
|
||||
rm -rf ${dir_temp}
|
||||
teardown() {
|
||||
rm -rf "${dir_temp}"
|
||||
|
||||
if [[ -d "${dir_debian}.bak" ]]; then
|
||||
mv ${dir_debian}.bak ${dir_debian}
|
||||
|
@ -72,5 +39,65 @@ load /code/scripts/common-run.sh
|
|||
mv ${dir_alpine}.bak ${dir_alpine}
|
||||
fi
|
||||
|
||||
do_postconf -e "daemon_directory=${old_daemon_directory}"
|
||||
cat "${temporary_file}" > /etc/postfix/main.cf
|
||||
rm -rf "${temporary_file}"
|
||||
}
|
||||
|
||||
@test "Test if Debian/Ubuntu directory remains the same when run on Debian/Ubuntu" {
|
||||
local daemon_directory
|
||||
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
error "$(ls -lah ${dir_temp})"
|
||||
cp -r "${dir_temp}/postfix" "${dir_debian}"
|
||||
do_postconf -e "daemon_directory=${dir_debian}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_debian}" ]
|
||||
}
|
||||
|
||||
@test "Test if Debian/Ubuntu directory gets changes the same when run on Alpine" {
|
||||
local daemon_directory
|
||||
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
cp -r "${dir_temp}/postfix" "${dir_debian}"
|
||||
do_postconf -e "daemon_directory=${dir_debian}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_alpine}" ]
|
||||
}
|
||||
|
||||
@test "Test if Alpine directory remains the same when run on Alpine" {
|
||||
local daemon_directory
|
||||
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
cp -r "${dir_temp}/postfix" "${dir_alpine}"
|
||||
do_postconf -e "daemon_directory=${dir_alpine}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_alpine}" ]
|
||||
}
|
||||
|
||||
@test "Test if Alpine directory gets changes the same when run on Debian/Ubuntu" {
|
||||
local daemon_directory
|
||||
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
cp -r "${dir_temp}/postfix" "${dir_alpine}"
|
||||
do_postconf -e "daemon_directory=${dir_alpine}"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_debian}" ]
|
||||
}
|
||||
|
||||
@test "Test if things work with custom directory" {
|
||||
local daemon_directory
|
||||
|
||||
do_postconf -e "daemon_directory=${dir_temp}/postfix"
|
||||
postfix_upgrade_daemon_directory
|
||||
postfix check
|
||||
rm -rf "${dir_debian}" "${dir_alpine}"
|
||||
[ "$(get_postconf "daemon_directory")" == "${dir_temp}" ]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue