]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - test/units/testsuite-26.sh
Merge pull request #25387 from yuwata/core-fix-gc-logic
[thirdparty/systemd.git] / test / units / testsuite-26.sh
index a8e7a5abaa7d80f97ab26b05f61bccd8466df9ef..2e0350aabe394aa8fd152fcec481a139d32311d3 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env bash
 # SPDX-License-Identifier: LGPL-2.1-or-later
+# shellcheck disable=SC2016
 set -eux
 set -o pipefail
 
@@ -10,19 +11,22 @@ set -o pipefail
 
 at_exit() {
     if [[ -v UNIT_NAME && -e "/usr/lib/systemd/system/$UNIT_NAME" ]]; then
-        rm -fv "/usr/lib/systemd/system/$UNIT_NAME"
+        rm -fvr "/usr/lib/systemd/system/$UNIT_NAME" "/etc/systemd/system/$UNIT_NAME.d" "+4"
     fi
 
     rm -f /etc/init.d/issue-24990
     return 0
 }
 
+# shellcheck source=test/units/assert.sh
+. "$(dirname "$0")"/assert.sh
+
 trap at_exit EXIT
 
 # Create a simple unit file for testing
 # Note: the service file is created under /usr on purpose to test
 #       the 'revert' verb as well
-UNIT_NAME="systemctl-test-$RANDOM.service"
+export UNIT_NAME="systemctl-test-$RANDOM.service"
 cat >"/usr/lib/systemd/system/$UNIT_NAME" <<\EOF
 [Unit]
 Description=systemctl test
@@ -46,7 +50,16 @@ EOF
 mkdir /run/systemd/system-preset/
 echo "disable $UNIT_NAME" >/run/systemd/system-preset/99-systemd-test.preset
 
-systemctl daemon-reload
+EDITOR='true' script -ec 'systemctl edit "$UNIT_NAME"' /dev/null
+[ ! -e "/etc/systemd/system/$UNIT_NAME.d/override.conf" ]
+
+printf '%s\n' '[Service]' 'ExecStart=' 'ExecStart=sleep 10d' > "+4"
+EDITOR='mv' script -ec 'systemctl edit "$UNIT_NAME"' /dev/null
+printf '%s\n' '[Service]' 'ExecStart=' 'ExecStart=sleep 10d' | cmp - "/etc/systemd/system/$UNIT_NAME.d/override.conf"
+
+printf '%b'   '[Service]\n' 'ExecStart=\n' 'ExecStart=sleep 10d' > "+4"
+EDITOR='mv' script -ec 'systemctl edit "$UNIT_NAME"' /dev/null
+printf '%s\n' '[Service]'   'ExecStart='   'ExecStart=sleep 10d' | cmp - "/etc/systemd/system/$UNIT_NAME.d/override.conf"
 
 # Argument help
 systemctl --state help
@@ -87,6 +100,16 @@ systemctl list-jobs --before
 systemctl list-jobs --after --before
 systemctl list-jobs "*"
 
+# is-* verbs
+# Should return 4 for a missing unit file
+assert_rc 4 systemctl --quiet is-active not-found.service
+assert_rc 4 systemctl --quiet is-failed not-found.service
+assert_rc 4 systemctl --quiet is-enabled not-found.service
+# is-active: return 3 when the unit exists but inactive
+assert_rc 3 systemctl --quiet is-active "$UNIT_NAME"
+# is-enabled: return 1 when the unit exists but disabled
+assert_rc 1 systemctl --quiet is-enabled "$UNIT_NAME"
+
 # Basic service management
 systemctl start --show-transaction "$UNIT_NAME"
 systemctl status -n 5 "$UNIT_NAME"