mirror of
https://github.com/ION606/MailPocket.git
synced 2026-05-14 22:06:55 +00:00
57 lines
1.6 KiB
Bash
57 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
CONTAINER_NAME="sqlite-server"
|
|
SERVER_URL="http://localhost:15521"
|
|
VOLUME_PATH="/app/data"
|
|
|
|
test_server_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() {
|
|
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_db_entry() {
|
|
DB_FILE="$VOLUME_PATH/emails.db"
|
|
FORM_NAME="testform"
|
|
|
|
# Use docker exec to check database inside container
|
|
if docker exec $CONTAINER_NAME /bin/sh -c "[ -f $DB_FILE ]"; then
|
|
result=$(docker exec $CONTAINER_NAME sqlite3 "$DB_FILE" \
|
|
"SELECT email FROM emails WHERE email='test@example.com' AND formname='$FORM_NAME';")
|
|
|
|
if [ "$result" == "test@example.com" ]; then
|
|
echo "✅ Entry found in database (form: $FORM_NAME)"
|
|
else
|
|
echo "❌ Entry not found in database"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "❌ Database file not found in container!"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Run tests
|
|
test_server_running
|
|
test_form_submission
|
|
sleep 2 # Allow time for async write
|
|
test_db_entry
|
|
|
|
echo "✅ All SQLite tests passed!" |