json-archive/tests/compression-integration/validate.sh

63 lines
1.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
#
# Validate that compressed and decompressed archives produce the same results.
# Run this after run_all.sh to smoke test the outputs.
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
BINARY="$PROJECT_DIR/target/debug/json-archive"
echo "=== Validation ==="
errors=0
for format in gzip brotli zstd; do
dir="$SCRIPT_DIR/out/$format"
if [ ! -d "$dir" ]; then
echo "SKIP: $format (no output directory)"
continue
fi
# Find the compressed and uncompressed files
compressed=$(find "$dir" -name "*.gz" -o -name "*.br" -o -name "*.zst" | head -1)
uncompressed="$dir/test.json.archive"
if [ ! -f "$compressed" ] || [ ! -f "$uncompressed" ]; then
echo "SKIP: $format (missing files)"
continue
fi
# Compare state output
state_compressed=$("$BINARY" state "$compressed")
state_uncompressed=$("$BINARY" state "$uncompressed")
if [ "$state_compressed" = "$state_uncompressed" ]; then
echo "OK: $format - state matches"
else
echo "FAIL: $format - state differs"
errors=$((errors + 1))
fi
# Compare observation count from info
count_compressed=$("$BINARY" info "$compressed" --output json | python3 -c "import sys,json; print(json.load(sys.stdin)['observation_count'])")
count_uncompressed=$("$BINARY" info "$uncompressed" --output json | python3 -c "import sys,json; print(json.load(sys.stdin)['observation_count'])")
if [ "$count_compressed" = "$count_uncompressed" ]; then
echo "OK: $format - observation count matches ($count_compressed)"
else
echo "FAIL: $format - observation count differs ($count_compressed vs $count_uncompressed)"
errors=$((errors + 1))
fi
done
echo ""
if [ $errors -eq 0 ]; then
echo "All validations passed."
else
echo "$errors validation(s) failed."
exit 1
fi