test: enable and fix the TEST-71 hostname wildcard test
test_wildcard() was never executed: run_testcases() only picks up functions named testcase_* so this test never ran. This commmit makes it run and fixes two issues in the test: 1. /etc/hostname is absent in the test image so we need to guard for that. 2. The pattern check was written as [[ "$P" == "$H" ]] with both sides quoted, but we need to one side unquoted as otherwise the comparison will always be false.
This commit is contained in:
@@ -266,20 +266,21 @@ test_varlink() {
|
||||
cmp "$A" "$B"
|
||||
}
|
||||
|
||||
test_wildcard() {
|
||||
SAVED="$(cat /etc/hostname)"
|
||||
testcase_wildcard() {
|
||||
SAVED=""
|
||||
[[ -f /etc/hostname ]] && SAVED="$(cat /etc/hostname)"
|
||||
trap 'hostnamectl set-hostname "$SAVED"' RETURN
|
||||
|
||||
P='foo-??-??.????bar'
|
||||
hostnamectl set-hostname "$P"
|
||||
H="$(hostname)"
|
||||
# Validate that the hostname is not the literal pattern, but matches the pattern shell style
|
||||
assert_neq "$H" "$P"
|
||||
[[ "$P" == "$H" ]]
|
||||
# shellcheck disable=SC2053 # glob matching is intended here
|
||||
[[ "$H" == $P ]]
|
||||
assert_eq "$(cat /etc/hostname)" "$P"
|
||||
|
||||
assert_in "Static hostname: foo-" "$(hostnamectl)"
|
||||
|
||||
hostnamectl set-hostname "$SAVED"
|
||||
}
|
||||
|
||||
teardown_hostnamed_alternate_paths() {
|
||||
|
||||
Reference in New Issue
Block a user