Files
platform-core/scripts/validate/test-k3s-local-recovery-lsblk.sh
T

44 lines
1.4 KiB
Bash

#!/usr/bin/env bash
# Regression test for whole-disk lsblk queries. Without --nodeps, lsblk emits
# the disk and all child partitions, while the validator requires one record.
set -Eeuo pipefail
readonly REPOSITORY_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd -P)"
readonly VALIDATOR_PATH="${REPOSITORY_ROOT}/scripts/validate/k3s-local-recovery.sh"
# shellcheck source=/dev/null
source "$VALIDATOR_PATH"
_k3slrv_exec() {
local scope="${1-}"
shift || return 1
[[ "$scope" == user ]] || return 1
if (( $# == 8 )) &&
[[ "$1" == /usr/bin/lsblk && "$2" == --noheadings &&
"$3" == --nodeps && "$4" == --paths && "$5" == --output &&
"$6" == MODEL && "$7" == -- && "$8" == /dev/fixture-disk ]]; then
printf '%s\n' FIXTURE_DISK_MODEL
else
# This mirrors lsblk against a whole disk when dependency traversal is
# not disabled: the disk row is followed by a child-partition row.
printf '%s\n%s\n' FIXTURE_DISK_MODEL FIXTURE_CHILD_ROW
fi
}
actual=''
if ! actual="$(_k3slrv_lsblk MODEL /dev/fixture-disk)"; then
printf '%s\n' \
'TEST FAILURE: whole-disk lsblk query did not produce one record' >&2
exit 1
fi
if [[ "$actual" != FIXTURE_DISK_MODEL ]]; then
printf '%s\n' \
'TEST FAILURE: whole-disk lsblk query returned an unexpected record' >&2
exit 1
fi
printf '%s\n' 'PASS: recovery validator excludes lsblk child rows'