Ensure that test checks data length (#2546)

wc has an optimization that can use metadata when stdin is set to a
file.  Also fix up logging.
This commit is contained in:
Andrew Gaul 2024-10-14 18:31:37 +09:00 committed by GitHub
parent c00b5fd4bb
commit 1d3ab76cc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -125,20 +125,21 @@ function check_file_size() {
local FILE_NAME="$1"
local EXPECTED_SIZE="$2"
# Verify file is zero length via metadata
# Verify file length via metadata
local size
size=$(get_size "${FILE_NAME}")
if [ "${size}" -ne "${EXPECTED_SIZE}" ]
then
echo "error: expected ${FILE_NAME} to be zero length"
echo "error: expected ${FILE_NAME} to be ${EXPECTED_SIZE} length but was ${size} via metadata"
return 1
fi
# Verify file is zero length via data
size=$(wc -c < "${FILE_NAME}")
# Verify file length via data
# shellcheck disable=SC2002
size=$(cat "${FILE_NAME}" | wc -c)
if [ "${size}" -ne "${EXPECTED_SIZE}" ]
then
echo "error: expected ${FILE_NAME} to be ${EXPECTED_SIZE} length, got ${size}"
echo "error: expected ${FILE_NAME} to be ${EXPECTED_SIZE} length, got ${size} via data"
return 1
fi
}