chiark / gitweb /
autopkgtests: Move much stuff into lib
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Dec 2021 00:42:38 +0000 (00:42 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Dec 2021 01:05:06 +0000 (01:05 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
tests/lib
tests/t-config

index bf56c46399c99b15f1ed6ce8622bcc463def3f9a..ab13175ce6b95e699ace01b461c40b7ef4195129 100644 (file)
--- a/tests/lib
+++ b/tests/lib
@@ -1,5 +1,14 @@
 # -*- shell-script -*-
 
+prep_tmp () {
+    tmp="${AUTOPKGTEST_ARTIFACTS}"
+    if [ "x$tmp" = x ]; then
+       rm -rf tmp
+       mkdir tmp
+       tmp=tmp
+    fi
+}
+
 expect_output () {
     local e_status=$1; shift
     local e_stdout=$1; shift
@@ -11,3 +20,37 @@ expect_output () {
     test "$g_status" = "$e_status"
     test "$g_stdout" = "$e_stdout"
 }
+
+prep_cuser () {
+    cuser=${1-bin}
+
+    cuser_uid=$(id -u $cuser)
+    cuser_gid=$(id -g $cuser)
+}
+
+prep_config_t_env () {
+    local suser="$1"
+    local cfgdir="$2"
+    mkdir -p "$cfgdir"/services.d
+    cat >$cfgdir/services.d/userv-t-env <<END
+if ( glob calling-user $cuser
+   & glob service-user $suser
+   )
+       execute printenv
+fi
+END
+}
+
+check_expected_env () {
+    local got_env="$1"
+
+    for expect in                                      \
+       "USERV_SERVICE=userv-t-env"                     \
+       "USERV_USER=$cuser"                             \
+       "USERV_GROUP=$cuser $cuser"                     \
+       "USERV_UID=$cuser_uid"                          \
+       "USERV_GID=$cuser_gid $cuser_gid"               \
+    ; do
+       egrep "^$expect\$" $got_env
+    done
+}
index b4ed7f3406b7162b33ed470b9869a5033f72620b..946f7b892b302822fc1681ad9c692319e0f5060f 100755 (executable)
@@ -3,40 +3,16 @@ set -ex
 
 . tests/lib
 
-(
-    cat >/etc/userv/services.d/userv-t-env <<END
-if ( glob calling-user bin
-   & glob service-user games
-   )
-       execute printenv
-fi
-END
-)
-
-tmp="${AUTOPKGTEST_ARTIFACTS}"
-if [ "x$tmp" = x ]; then
-    rm -rf tmp
-    mkdir tmp
-    tmp=tmp
-fi
-
-bin_uid=$(id -u bin)
-bin_gid=$(id -g bin)
+prep_tmp
+prep_cuser
+prep_config_t_env games /etc/userv
 
 : '---------- test service invocation ----------'
 
-really -u bin \
+really -u $cuser \
 userv games userv-t-env >"$tmp"/env
 
-for expect in                                  \
-    'USERV_SERVICE=userv-t-env'                        \
-    'USERV_USER=bin'                           \
-    'USERV_GROUP=bin bin'                      \
-    "USERV_UID=$bin_uid"                       \
-    "USERV_GID=$bin_gid $bin_gid"              \
-; do
-    egrep "^$expect\$" "$tmp"/env
-done
+check_expected_env "$tmp"/env
 
 : '---------- test rejection (wrong calling user) ----------'