#!/bin/bash # Unit test for wakaapi component # Following TDD: Write test → Execute test → Test fails → Write minimal code to pass test set -e # Load environment settings SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ENV_FILE="${SCRIPT_DIR}/TSYSDevStack-SupportStack-Demo-Settings" if [ ! -f "$ENV_FILE" ]; then echo "Error: Environment settings file not found at $ENV_FILE" exit 1 fi source "$ENV_FILE" # Test function to validate wakaapi test_wakaapi() { echo "Testing wakaapi availability and functionality..." # Check if the container exists and is running if docker ps | grep -q "$WAKAAPI_NAME"; then echo "✓ wakaapi container is running" else echo "✗ wakaapi container is NOT running" return 1 fi # Test if wakaapi is accessible on the expected port (after allowing some startup time) sleep 15 # Allow time for wakaapi to fully start # Try the main endpoint (health check might not be at /api in Wakapi) # WakaAPI is a Go-based web app that listens on port 3000 if curl -f -s "http://$BIND_ADDRESS:$WAKAAPI_PORT/" > /dev/null; then echo "✓ wakaapi is accessible via HTTP" else echo "✗ wakaapi is NOT accessible via HTTP at http://$BIND_ADDRESS:$WAKAAPI_PORT/" return 1 fi echo "✓ Basic wakaapi test passed" return 0 } # Execute the test if test_wakaapi; then echo "✓ wakaapi test PASSED" exit 0 else echo "✗ wakaapi test FAILED" exit 1 fi