summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2022-05-18 19:35:32 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2022-05-18 19:40:28 +0000
commitea29b6c763a3695595c1a6aa0c614e4127019817 (patch)
treeba92262a5a7a6d53829abc842b26cc5b875d2c9c
parent10480664171a28d0b64670f4941bdc32e8a355ee (diff)
downloadalpine-conf-ea29b6c763a3695595c1a6aa0c614e4127019817.zip
setup-timezone: add test
Make it testable
-rw-r--r--setup-timezone.in6
-rwxr-xr-xtests/setup_timezone_test14
2 files changed, 16 insertions, 4 deletions
diff --git a/setup-timezone.in b/setup-timezone.in
index 2a17848..0ee83eb 100644
--- a/setup-timezone.in
+++ b/setup-timezone.in
@@ -4,7 +4,7 @@ PREFIX=@PREFIX@
: ${LIBDIR=$PREFIX/lib}
. "$LIBDIR/libalpine.sh"
-zroot=/usr/share/zoneinfo
+zroot="$ROOT"/usr/share/zoneinfo
usage() {
cat <<-__EOF__
@@ -83,7 +83,7 @@ else
apkdel=".setup-timezone"
fi
-apk add --quiet $pkg
+$MOCK apk add --quiet $pkg
if [ -L "${ROOT}"etc/zoneinfo/localtime ]; then
default_timezone=$(readlink "${ROOT}"etc/zoneinfo/localtime)
@@ -124,5 +124,5 @@ while true; do
done
if [ -n "$apkdel" ]; then
- apk del --quiet $apkdel
+ $MOCK apk del --quiet $apkdel
fi
diff --git a/tests/setup_timezone_test b/tests/setup_timezone_test
index 53fccd9..68ca961 100755
--- a/tests/setup_timezone_test
+++ b/tests/setup_timezone_test
@@ -2,9 +2,21 @@
. $(atf_get_srcdir)/test_env.sh
init_tests \
- setup_timezone_usage
+ setup_timezone_usage \
+ setup_timezone_copy \
setup_timezone_usage_body() {
test_usage setup-timezone
}
+setup_timezone_copy_body() {
+ init_env
+ mkdir -p usr/share/zoneinfo/Europe
+ touch usr/share/zoneinfo/Europe/Oslo
+ atf_check -s exit:0 \
+ -o match:"apk add .*tzdata" \
+ -o match:"apk del" \
+ -e empty \
+ setup-timezone Europe/Oslo
+}
+