#!/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