1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

test: import hostnamed tests from debian/ubuntu test suite

This commit is contained in:
Yu Watanabe 2022-06-14 09:03:00 +09:00
parent aab61a8c99
commit 39f4546199
4 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1 @@
../TEST-01-BASIC/Makefile

10
test/TEST-71-HOSTNAME/test.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
TEST_DESCRIPTION="test hostnamed"
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
do_test "$@"

View File

@ -0,0 +1,10 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Unit]
Description=TEST-71-HOSTNAME
[Service]
ExecStartPre=rm -f /failed /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
StandardOutput=journal+console
StandardError=journal+console
Type=oneshot

52
test/units/testsuite-71.sh Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
set -o pipefail
# shellcheck source=test/units/assert.sh
. "$(dirname "$0")"/assert.sh
restore_hostname() {
if [[ -e /tmp/hostname.bak ]]; then
mv /tmp/hostname.bak /etc/hostname
else
rm -f /etc/hostname
fi
}
test_hostname() {
local orig=
if [[ -f /etc/hostname ]]; then
cp /etc/hostname /tmp/hostname.bak
orig=$(cat /etc/hostname)
fi
trap restore_hostname RETURN
# should activate daemon and work
if [[ -n "$orig" ]]; then
assert_in "Static hostname: $orig" "$(hostnamectl)"
fi
assert_in "Kernel: $(uname -s) $(uname -r)" "$(hostnamectl)"
# change hostname
assert_rc 0 hostnamectl set-hostname testhost
assert_eq "$(cat /etc/hostname)" "testhost"
assert_in "Static hostname: testhost" "$(hostnamectl)"
if [[ -n "$orig" ]]; then
# reset to original
assert_rc 0 hostnamectl set-hostname "$orig"
assert_eq "$(cat /etc/hostname)" "$orig"
assert_in "Static hostname: $orig" "$(hostnamectl)"
fi
}
: >/failed
test_hostname
touch /testok
rm /failed