2025-02-08 13:05:53 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2025-02-28 19:11:16 -05:00
|
|
|
CONTAINER_NAME="batched-server"
|
2025-02-24 18:53:25 -05:00
|
|
|
SERVER_URL="http://localhost:15521"
|
2025-02-28 19:11:16 -05:00
|
|
|
VOLUME_PATH="/app/data" # Path inside container
|
2025-02-08 13:05:53 -05:00
|
|
|
|
|
|
|
|
test_server_running() {
|
|
|
|
|
echo "Testing if the server is running..."
|
|
|
|
|
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$SERVER_URL/")
|
|
|
|
|
|
|
|
|
|
if [ "$RESPONSE" -eq 200 ]; then
|
|
|
|
|
echo "✅ Server is running (Status: 200 OK)"
|
|
|
|
|
else
|
|
|
|
|
echo "❌ Server is NOT running (Received status: $RESPONSE)"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 19:11:16 -05:00
|
|
|
test_form_submission() {
|
|
|
|
|
echo "Testing form submission to dynamic endpoint..."
|
|
|
|
|
FORM_NAME="testform"
|
|
|
|
|
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "email=test@example.com" "$SERVER_URL/$FORM_NAME")
|
2025-02-08 13:05:53 -05:00
|
|
|
|
|
|
|
|
if [ "$RESPONSE" -eq 200 ]; then
|
2025-02-28 19:11:16 -05:00
|
|
|
echo "✅ Form submission to /$FORM_NAME successful (Status: 200 OK)"
|
2025-02-08 13:05:53 -05:00
|
|
|
else
|
2025-02-28 19:11:16 -05:00
|
|
|
echo "❌ Form submission failed (Received status: $RESPONSE)"
|
2025-02-08 13:05:53 -05:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test_csv_written() {
|
2025-02-28 19:11:16 -05:00
|
|
|
CSV_FILE="$VOLUME_PATH/emails.csv"
|
|
|
|
|
FORM_NAME="testform"
|
2025-02-08 13:05:53 -05:00
|
|
|
|
2025-02-28 19:11:16 -05:00
|
|
|
# Use docker exec to check CSV inside container
|
|
|
|
|
if docker exec $CONTAINER_NAME /bin/sh -c "[ -f $CSV_FILE ]"; then
|
|
|
|
|
if docker exec $CONTAINER_NAME grep -q "test@example.com,$FORM_NAME" "$CSV_FILE"; then
|
|
|
|
|
echo "✅ Entry found in CSV (form: $FORM_NAME)"
|
2025-02-08 13:05:53 -05:00
|
|
|
else
|
2025-02-28 19:11:16 -05:00
|
|
|
echo "❌ Entry NOT found in CSV"
|
2025-02-08 13:05:53 -05:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
else
|
2025-02-28 19:11:16 -05:00
|
|
|
echo "❌ CSV file not found in container!"
|
2025-02-08 13:05:53 -05:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 19:11:16 -05:00
|
|
|
# Run tests
|
2025-02-08 13:05:53 -05:00
|
|
|
test_server_running
|
2025-02-28 19:11:16 -05:00
|
|
|
test_form_submission
|
|
|
|
|
sleep 2 # Allow time for batched write
|
2025-02-08 13:05:53 -05:00
|
|
|
test_csv_written
|
|
|
|
|
|
2025-02-28 19:11:16 -05:00
|
|
|
echo "✅ All batched CSV tests passed!"
|