]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-46-HOMED: modernize test
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Jul 2025 03:27:18 +0000 (12:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Jul 2025 03:27:25 +0000 (12:27 +0900)
- use command to check the existence of homectl,
- use timeout for waiting user,
- use 4ch indentation.

test/units/TEST-46-HOMED.sh

index e69323df53a8c2849eb041f50a6a06d11b9bb17b..2c0dbd22a9a8243331577f6f4be8f6b188bf0aed 100755 (executable)
@@ -6,9 +6,9 @@ set -eux
 set -o pipefail
 
 # Check if homectl is installed, and if it isn't bail out early instead of failing
-if ! test -x /usr/bin/homectl ; then
-        echo "no homed" >/skipped
-        exit 77
+if ! command -v homectl >/dev/null; then
+    echo "no homed" >/skipped
+    exit 77
 fi
 
 inspect() {
@@ -29,19 +29,11 @@ inspect() {
 }
 
 wait_for_exist() {
-    # 2min max
-    for i in {1..60}; do
-        (( i > 1 )) && sleep 2
-        homectl inspect "$1" && break
-    done
+    timeout 2m bash -c "until homectl inspect '${1:?}'; do sleep 2; done"
 }
 
 wait_for_state() {
-    # 2min max
-    for i in {1..60}; do
-        (( i > 1 )) && sleep 2
-        homectl inspect "$1" | grep -qF "State: $2" && break
-    done
+    timeout 2m bash -c "until homectl inspect '${1:?}' | grep -qF 'State: $2'; do sleep 2; done"
 }
 
 FSTYPE="$(stat --file-system --format "%T" /)"
@@ -123,32 +115,32 @@ inspect test-user
 # Do some keyring tests, but only on real kernels, since keyring access inside of containers will fail
 # (See: https://github.com/systemd/systemd/issues/17606)
 if ! systemd-detect-virt -cq ; then
-        PASSWORD=xEhErW0ndafV4s homectl activate test-user
-        inspect test-user
+    PASSWORD=xEhErW0ndafV4s homectl activate test-user
+    inspect test-user
 
-        # Key should now be in the keyring
-        homectl update test-user --real-name "Keyring Test"
-        inspect test-user
+    # Key should now be in the keyring
+    homectl update test-user --real-name "Keyring Test"
+    inspect test-user
 
-        # These commands shouldn't use the keyring
-        (! timeout 5s homectl authenticate test-user )
-        (! NEWPASSWORD="foobar" timeout 5s homectl passwd test-user )
+    # These commands shouldn't use the keyring
+    (! timeout 5s homectl authenticate test-user )
+    (! NEWPASSWORD="foobar" timeout 5s homectl passwd test-user )
 
-        homectl lock test-user
-        inspect test-user
+    homectl lock test-user
+    inspect test-user
 
-        # Key should be gone from keyring
-        (! timeout 5s homectl update test-user --real-name "Keyring Test 2" )
+    # Key should be gone from keyring
+    (! timeout 5s homectl update test-user --real-name "Keyring Test 2" )
 
-        PASSWORD=xEhErW0ndafV4s homectl unlock test-user
-        inspect test-user
+    PASSWORD=xEhErW0ndafV4s homectl unlock test-user
+    inspect test-user
 
-        # Key should have been re-instantiated into the keyring
-        homectl update test-user --real-name "Keyring Test 3"
-        inspect test-user
+    # Key should have been re-instantiated into the keyring
+    homectl update test-user --real-name "Keyring Test 3"
+    inspect test-user
 
-        homectl deactivate test-user
-        inspect test-user
+    homectl deactivate test-user
+    inspect test-user
 fi
 
 # Do some resize tests, but only if we run on real kernels and are on btrfs, as quota inside of containers
@@ -242,13 +234,13 @@ homectl remove test-user
 # blob directory tests
 # See docs/USER_RECORD_BLOB_DIRS.md
 checkblob() {
-        test -f "/var/cache/systemd/home/blob-user/$1"
-        stat -c "%u %#a" "/var/cache/systemd/home/blob-user/$1" | grep "^0 0644"
-        test -f "/home/blob-user/.identity-blob/$1"
-        stat -c "%u %#a" "/home/blob-user/.identity-blob/$1" | grep "^12345 0644"
+    test -f "/var/cache/systemd/home/blob-user/$1"
+    stat -c "%u %#a" "/var/cache/systemd/home/blob-user/$1" | grep "^0 0644"
+    test -f "/home/blob-user/.identity-blob/$1"
+    stat -c "%u %#a" "/home/blob-user/.identity-blob/$1" | grep "^12345 0644"
 
-        diff "/var/cache/systemd/home/blob-user/$1" "$2"
-        diff "/var/cache/systemd/home/blob-user/$1" "/home/blob-user/.identity-blob/$1"
+    diff "/var/cache/systemd/home/blob-user/$1" "$2"
+    diff "/var/cache/systemd/home/blob-user/$1" "/home/blob-user/.identity-blob/$1"
 }
 
 mkdir /tmp/blob1 /tmp/blob2