test: support debian/ubuntu specific timezone config file

This commit is contained in:
Yu Watanabe
2022-06-14 20:52:44 +09:00
parent 8ed2103306
commit aab61a8c99
+24
View File
@@ -7,9 +7,24 @@ set -o pipefail
# shellcheck source=test/units/assert.sh
. "$(dirname "$0")"/assert.sh
restore_timezone() {
if [[ -f /tmp/timezone.bak ]]; then
mv /tmp/timezone.bak /etc/timezone
else
rm -f /etc/timezone
fi
}
test_timezone() {
local ORIG_TZ=
# Debian/Ubuntu specific file
if [[ -f /etc/timezone ]]; then
mv /etc/timezone /tmp/timezone.bak
fi
trap restore_timezone EXIT
if [[ -L /etc/localtime ]]; then
ORIG_TZ=$(readlink /etc/localtime | sed 's#^.*zoneinfo/##')
echo "original tz: $ORIG_TZ"
@@ -21,13 +36,22 @@ test_timezone() {
echo 'change timezone'
assert_eq "$(timedatectl --no-pager set-timezone Europe/Kiev 2>&1)" ""
assert_eq "$(readlink /etc/localtime | sed 's#^.*zoneinfo/##')" "Europe/Kiev"
if [[ -f /etc/timezone ]]; then
assert_eq "$(cat /etc/timezone)" "Europe/Kiev"
fi
assert_in "Time zone: Europe/Kiev \(EEST, \+0[0-9]00\)" "$(timedatectl)"
if [[ -n "$ORIG_TZ" ]]; then
echo 'reset timezone to original'
assert_eq "$(timedatectl set-timezone "$ORIG_TZ" 2>&1)" ""
assert_eq "$(readlink /etc/localtime | sed 's#^.*zoneinfo/##')" "$ORIG_TZ"
if [[ -f /etc/timezone ]]; then
assert_eq "$(cat /etc/timezone)" "$ORIG_TZ"
fi
fi
restore_timezone
trap - EXIT
}
restore_adjtime() {