105 lines
2.8 KiB
Bash
Executable File
105 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
echo "==================================================================="
|
|
echo "Gallery Generator Container Test Suite with Coverage"
|
|
echo "==================================================================="
|
|
echo
|
|
|
|
# Check if we're in the right directory
|
|
if [[ ! -f "Singularity.def" ]]; then
|
|
echo "❌ Error: Singularity.def not found. Please run from project root."
|
|
exit 1
|
|
fi
|
|
|
|
# Check for apptainer/singularity
|
|
CONTAINER_CMD=""
|
|
if command -v apptainer &> /dev/null; then
|
|
CONTAINER_CMD="apptainer"
|
|
elif command -v singularity &> /dev/null; then
|
|
CONTAINER_CMD="singularity"
|
|
else
|
|
echo "❌ Error: Neither 'apptainer' nor 'singularity' found."
|
|
echo "Please install Apptainer/Singularity to run container tests."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Using container runtime: $CONTAINER_CMD"
|
|
echo
|
|
|
|
# Container file
|
|
CONTAINER_FILE="gallery-test.sif"
|
|
|
|
# Clean up any existing container
|
|
if [[ -f "$CONTAINER_FILE" ]]; then
|
|
echo "🧹 Removing existing container..."
|
|
rm -f "$CONTAINER_FILE"
|
|
fi
|
|
|
|
echo "🔨 Building container..."
|
|
echo "Command: $CONTAINER_CMD build $CONTAINER_FILE Singularity.def"
|
|
echo
|
|
|
|
if ! $CONTAINER_CMD build "$CONTAINER_FILE" Singularity.def; then
|
|
echo "❌ Container build failed!"
|
|
exit 1
|
|
fi
|
|
|
|
echo
|
|
echo "✅ Container built successfully!"
|
|
echo "Container size: $(du -h "$CONTAINER_FILE" | cut -f1)"
|
|
echo
|
|
|
|
echo "🧪 Running container build tests..."
|
|
echo
|
|
if ! python3 tests/test_build_container.py; then
|
|
echo "❌ Container build tests failed!"
|
|
exit 1
|
|
fi
|
|
|
|
echo
|
|
echo "🧪 Running tests inside container..."
|
|
echo
|
|
if ! $CONTAINER_CMD exec "$CONTAINER_FILE" python3 /src/tests/test_container.py; then
|
|
echo "❌ Container tests failed!"
|
|
exit 1
|
|
fi
|
|
|
|
echo
|
|
echo "🧪 Testing container runtime..."
|
|
echo
|
|
echo "Python version in container:"
|
|
$CONTAINER_CMD exec "$CONTAINER_FILE" python3 --version
|
|
|
|
echo
|
|
echo "Installed packages:"
|
|
$CONTAINER_CMD exec "$CONTAINER_FILE" pip list
|
|
|
|
echo
|
|
echo "Testing ImageMagick:"
|
|
$CONTAINER_CMD exec "$CONTAINER_FILE" convert -version | head -n 2
|
|
|
|
echo
|
|
echo "🧪 Running automated coverage tests..."
|
|
$CONTAINER_CMD exec "$CONTAINER_FILE" python3 /src/tests/run_coverage.py
|
|
|
|
echo
|
|
echo "==================================================================="
|
|
echo "✅ ALL TESTS PASSED!"
|
|
echo "Container is ready for use with coverage analysis completed."
|
|
echo "==================================================================="
|
|
echo
|
|
echo "To use the container:"
|
|
echo " $CONTAINER_CMD run $CONTAINER_FILE [args]"
|
|
echo " $CONTAINER_CMD exec $CONTAINER_FILE python3 /src/generate_gallery.py [args]"
|
|
echo " $CONTAINER_CMD exec $CONTAINER_FILE python3 /src/tests/run_coverage.py # Run coverage tests"
|
|
echo
|
|
|
|
# Optional: Clean up
|
|
read -p "Remove test container? (y/N) " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
rm -f "$CONTAINER_FILE"
|
|
echo "🧹 Test container removed."
|
|
fi
|