naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
594167
From 10d03dd6ea51b99488dcfa5e85c85fbddc86a243 Mon Sep 17 00:00:00 2001
594167
From: David Tardon <dtardon@redhat.com>
594167
Date: Sun, 17 Jul 2022 15:35:22 +0200
594167
Subject: [PATCH] test: add a simple test for list-users
594167
594167
(cherry picked from commit 6083f7a604267d02a648c76edd3e0cb7b83b4620)
594167
594167
Related: #2100464
594167
---
594167
 test/units/testsuite-35.sh | 20 ++++++++++++++++++++
594167
 1 file changed, 20 insertions(+)
594167
594167
diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh
594167
index 4fb2944e2d..28022b03cf 100755
594167
--- a/test/units/testsuite-35.sh
594167
+++ b/test/units/testsuite-35.sh
594167
@@ -225,6 +225,8 @@ cleanup_session() (
594167
     rm -rf /run/systemd/system/getty@tty2.service.d
594167
     systemctl daemon-reload
594167
 
594167
+    loginctl disable-linger logind-test-user
594167
+
594167
     pkill -u "$(id -u logind-test-user)"
594167
     sleep 1
594167
     pkill -KILL -u "$(id -u logind-test-user)"
594167
@@ -388,6 +390,23 @@ test_session_properties() {
594167
     /usr/lib/systemd/tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}"
594167
 }
594167
 
594167
+test_list_users() {
594167
+    if [[ ! -c /dev/tty2 ]]; then
594167
+        echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
594167
+        return
594167
+    fi
594167
+
594167
+    trap cleanup_session RETURN
594167
+    create_session
594167
+
594167
+    assert_eq "$(loginctl list-users --no-legend | awk '$2 == "logind-test-user" { print $1 }')" "$(id -ru logind-test-user)"
594167
+    assert_eq "$(loginctl  show-user --property Linger --value logind-test-user)" no
594167
+
594167
+    loginctl enable-linger logind-test-user
594167
+
594167
+    assert_eq "$(loginctl  show-user --property Linger --value logind-test-user)" yes
594167
+}
594167
+
594167
 : >/failed
594167
 
594167
 setup_test_user
594167
@@ -398,6 +417,7 @@ test_suspend_on_lid
594167
 test_shutdown
594167
 test_session
594167
 test_session_properties
594167
+test_list_users
594167
 
594167
 touch /testok
594167
 rm /failed