]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-26-SYSTEMCTL: test about systemctl return codes for is-* verbs 25689/head
authorMike Yuan <me@yhndnzj.com>
Mon, 12 Dec 2022 16:39:31 +0000 (00:39 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 13 Dec 2022 17:43:28 +0000 (01:43 +0800)
We should return 4 when no unit file is found.

See also: #25689 #25680

test/units/testsuite-26.sh

index 7c7a12b1ae5a683c07b6063bfaba2e97969651fc..70fdc5956e56f4d574dded1e47affdcb4a95810f 100755 (executable)
@@ -9,6 +9,9 @@ at_exit() {
     fi
 }
 
+# shellcheck source=test/units/assert.sh
+. "$(dirname "$0")"/assert.sh
+
 trap at_exit EXIT
 
 # Create a simple unit file for testing
@@ -79,6 +82,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"