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:
parent
aab61a8c99
commit
39f4546199
1
test/TEST-71-HOSTNAME/Makefile
Symbolic link
1
test/TEST-71-HOSTNAME/Makefile
Symbolic link
@ -0,0 +1 @@
|
||||
../TEST-01-BASIC/Makefile
|
10
test/TEST-71-HOSTNAME/test.sh
Executable file
10
test/TEST-71-HOSTNAME/test.sh
Executable 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 "$@"
|
10
test/units/testsuite-71.service
Normal file
10
test/units/testsuite-71.service
Normal 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
52
test/units/testsuite-71.sh
Executable 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
|
Loading…
Reference in New Issue
Block a user