mirror of
https://github.com/ION606/MailPocket.git
synced 2026-05-14 22:06:55 +00:00
56 lines
1.6 KiB
Bash
56 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
CONTAINER_NAME="batched-server"
|
|
SERVER_URL="http://localhost:15521"
|
|
VOLUME_PATH="/app/data" # Path inside container
|
|
|
|
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
|
|
}
|
|
|
|
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")
|
|
|
|
if [ "$RESPONSE" -eq 200 ]; then
|
|
echo "✅ Form submission to /$FORM_NAME successful (Status: 200 OK)"
|
|
else
|
|
echo "❌ Form submission failed (Received status: $RESPONSE)"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
test_csv_written() {
|
|
CSV_FILE="$VOLUME_PATH/emails.csv"
|
|
FORM_NAME="testform"
|
|
|
|
# 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)"
|
|
else
|
|
echo "❌ Entry NOT found in CSV"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "❌ CSV file not found in container!"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Run tests
|
|
test_server_running
|
|
test_form_submission
|
|
sleep 2 # Allow time for batched write
|
|
test_csv_written
|
|
|
|
echo "✅ All batched CSV tests passed!" |