]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add testsuite-74.machinectl 26771/head
authorMike Yuan <me@yhndnzj.com>
Mon, 13 Mar 2023 12:33:36 +0000 (20:33 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 15 Mar 2023 11:56:19 +0000 (19:56 +0800)
test/TEST-74-AUX-UTILS/test.sh
test/units/testsuite-74.machinectl.sh [new file with mode: 0755]

index f422c89141dfaa39154bede4b32f4c8a16a09468..94bb1594647b3375414e53019d1d4a5af6a253a0 100755 (executable)
@@ -7,4 +7,8 @@ TEST_DESCRIPTION="Tests for auxiliary utilities"
 # shellcheck source=test/test-functions
 . "${TEST_BASE_DIR:?}/test-functions"
 
+test_append_files() (
+        image_install script
+)
+
 do_test "$@"
diff --git a/test/units/testsuite-74.machinectl.sh b/test/units/testsuite-74.machinectl.sh
new file mode 100755 (executable)
index 0000000..4adb1cd
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# shellcheck disable=SC2016
+set -eux
+set -o pipefail
+
+# shellcheck source=test/units/assert.sh
+. "$(dirname "$0")"/assert.sh
+
+: >/failed
+
+at_exit() {
+    if [[ -v NSPAWN_NAME && -e "/var/lib/machines/$NSPAWN_NAME" ]]; then
+        rm -fvr "/var/lib/machines/$NSPAWN_NAME" "/etc/systemd/nspawn/$NSPAWN_NAME" "new"
+    fi
+
+    return 0
+}
+
+trap at_exit EXIT
+
+export NSPAWN_NAME="machinectl-test-$RANDOM.nspawn"
+cat >"/var/lib/machines/$NSPAWN_NAME" <<\EOF
+[Exec]
+Boot=true
+EOF
+
+EDITOR='true' script -ec 'machinectl edit "$NSPAWN_NAME"' /dev/null
+[ -f "/etc/systemd/nspawn/$NSPAWN_NAME" ]
+cmp "/var/lib/machines/$NSPAWN_NAME" "/etc/systemd/nspawn/$NSPAWN_NAME"
+
+cat >new <<\EOF
+[Exec]
+Boot=false
+EOF
+
+script -ec 'machinectl cat "$PWD/new"' /dev/null
+
+EDITOR='mv new' script -ec 'machinectl edit "$NSPAWN_NAME"' /dev/null
+printf '%s\n' '[Exec]' 'Boot=false' | cmp - "/etc/systemd/nspawn/$NSPAWN_NAME"
+
+touch /testok
+rm /failed