test: add testsuite-74.machinectl

This commit is contained in:
Mike Yuan
2023-03-13 20:33:36 +08:00
parent 1ed35a0d93
commit af0292844d
2 changed files with 47 additions and 0 deletions

View File

@@ -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 "$@"

View File

@@ -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