Add randomized data to tests for better verification

This commit is contained in:
Leopere 2025-03-20 22:25:37 -04:00
parent 9450ff041c
commit f1a25f959e
1 changed files with 62 additions and 13 deletions

View File

@ -6,6 +6,19 @@ TEST_TYPE=${1:-"all"}
# Set to 1 to keep temporary files, 0 to clean them up
KEEP_TEMP_FILES=${2:-0}
# Function to generate a random file with predictable size
generate_random_file() {
local OUTPUT=$1
local SIZE=$2
dd if=/dev/urandom bs=1 count=$SIZE of="$OUTPUT" 2>/dev/null
}
# Generate random string (for file contents)
generate_random_string() {
local LENGTH=$1
tr -dc A-Za-z0-9 </dev/urandom | head -c $LENGTH
}
cleanup_files() {
if [ "$KEEP_TEMP_FILES" -eq 0 ]; then
echo "=== CLEANING UP TEMPORARY FILES ==="
@ -32,13 +45,18 @@ run_basic_test() {
mkdir -p /tmp/complex/dir1/subdir2
mkdir -p /tmp/complex/dir2/subdir1
# Create files at different levels
echo 'root level file' > /tmp/complex/rootfile.txt
echo 'level 1 file in dir1' > /tmp/complex/dir1/file1.txt
echo 'level 1 file in dir2' > /tmp/complex/dir2/file2.txt
echo 'level 2 file in subdir1' > /tmp/complex/dir1/subdir1/file3.txt
echo 'level 2 file in subdir2' > /tmp/complex/dir1/subdir2/file4.txt
echo 'level 3 file in subsubdir1' > /tmp/complex/dir1/subdir1/subsubdir1/file5.txt
# Create files at different levels with random content
echo "root level file ($(generate_random_string 8))" > /tmp/complex/rootfile.txt
echo "level 1 file in dir1 ($(generate_random_string 12))" > /tmp/complex/dir1/file1.txt
echo "level 1 file in dir2 ($(generate_random_string 16))" > /tmp/complex/dir2/file2.txt
echo "level 2 file in subdir1 ($(generate_random_string 10))" > /tmp/complex/dir1/subdir1/file3.txt
echo "level 2 file in subdir2 ($(generate_random_string 14))" > /tmp/complex/dir1/subdir2/file4.txt
echo "level 3 file in subsubdir1 ($(generate_random_string 20))" > /tmp/complex/dir1/subdir1/subsubdir1/file5.txt
# Add random binary files of different sizes
generate_random_file "/tmp/complex/random_binary_small.bin" 512
generate_random_file "/tmp/complex/dir1/random_binary_medium.bin" 2048
generate_random_file "/tmp/complex/dir2/random_binary_large.bin" 8192
# Create a symbolic link with a relative path instead of absolute
cd /tmp/complex/dir2 && ln -s ../rootfile.txt symlink.txt && cd /workdir
@ -76,6 +94,17 @@ run_basic_test() {
cat /tmp/complex-extracted/complex-app/dir1/subdir1/subsubdir1/file5.txt
echo ' <-- Extracted: deep nested file5.txt'
# Verify binary file MD5 hashes specifically
echo '=== VERIFYING BINARY FILE MD5 HASHES ==='
md5sum /tmp/complex/random_binary_small.bin
md5sum /tmp/complex-extracted/complex-app/random_binary_small.bin
md5sum /tmp/complex/dir1/random_binary_medium.bin
md5sum /tmp/complex-extracted/complex-app/dir1/random_binary_medium.bin
md5sum /tmp/complex/dir2/random_binary_large.bin
md5sum /tmp/complex-extracted/complex-app/dir2/random_binary_large.bin
# Test symlink
echo '=== TESTING SYMLINK ==='
ls -la /tmp/complex/dir2/symlink.txt
@ -144,12 +173,32 @@ run_tar_comparison_test() {
mkdir -p /tmp/standard-test/data/user/pictures
mkdir -p /tmp/standard-test/logs
# Create various file types
echo '{"app": "tarballer", "version": "1.0"}' > /tmp/standard-test/config/settings/app.json
echo 'debug=true' > /tmp/standard-test/config/settings/debug.conf
dd if=/dev/urandom bs=1K count=10 of=/tmp/standard-test/data/user/documents/binary.dat 2>/dev/null
echo 'Test log entry 1' > /tmp/standard-test/logs/app.log
echo 'Test log entry 2' >> /tmp/standard-test/logs/app.log
# Create various file types with random content
echo "{\"app\": \"tarballer\", \"version\": \"1.0\", \"random_data\": \"$(generate_random_string 32)\"}" > /tmp/standard-test/config/settings/app.json
echo "debug=true\nlog_level=$(generate_random_string 5)\ndate_format=\"$(generate_random_string 8)\"" > /tmp/standard-test/config/settings/debug.conf
# Create binary files of different sizes
generate_random_file "/tmp/standard-test/data/user/documents/binary.dat" 10240
generate_random_file "/tmp/standard-test/data/user/pictures/image1.raw" 5120
generate_random_file "/tmp/standard-test/data/user/pictures/image2.raw" 7168
# Create log files with random entries
echo "Test log entry 1 - $(generate_random_string 16)" > /tmp/standard-test/logs/app.log
echo "Test log entry 2 - $(generate_random_string 24)" >> /tmp/standard-test/logs/app.log
echo "Test log entry 3 - $(generate_random_string 20)" >> /tmp/standard-test/logs/app.log
# Create text file with random data
generate_random_string 1024 > /tmp/standard-test/data/user/documents/text_file.txt
# Create config file with mixed content
cat << EOF > /tmp/standard-test/config/mixed_content.conf
# Configuration file with mixed content
SERVER_NAME=$(generate_random_string 12)
PORT=8080
MAX_CONNECTIONS=100
TIMEOUT=30
RANDOM_SEED=$(generate_random_string 64)
EOF
# Create symlinks
ln -s ../config/settings/app.json /tmp/standard-test/data/config-link.json