Files
MailPocket/test/sqlite.sh
T

57 lines
1.6 KiB
Bash
Raw Normal View History

2025-02-08 13:05:53 -05:00
#!/bin/bash
2025-02-28 19:11:16 -05:00
CONTAINER_NAME="sqlite-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"
2025-02-08 13:05:53 -05:00
test_server_running() {
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$SERVER_URL/")
if [ "$RESPONSE" -eq 200 ]; then
2025-02-28 19:11:16 -05:00
echo "✅ Server is running (status: 200 OK)"
2025-02-08 13:05:53 -05:00
else
2025-02-28 19:11:16 -05:00
echo "❌ Server is not running (received status: $RESPONSE)"
exit 1
2025-02-08 13:05:53 -05:00
fi
}
2025-02-28 19:11:16 -05:00
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")
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)"
exit 1
2025-02-08 13:05:53 -05:00
fi
}
test_db_entry() {
2025-02-28 19:11:16 -05:00
DB_FILE="$VOLUME_PATH/emails.db"
FORM_NAME="testform"
2025-02-08 13:05:53 -05:00
2025-02-28 19:11:16 -05:00
# 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';")
2025-02-08 13:05:53 -05:00
if [ "$result" == "test@example.com" ]; then
2025-02-28 19:11:16 -05:00
echo "✅ Entry found in database (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 database"
exit 1
fi
2025-02-08 13:05:53 -05:00
else
2025-02-28 19:11:16 -05:00
echo "❌ Database file not found in container!"
exit 1
2025-02-08 13:05:53 -05:00
fi
}
2025-02-28 19:11:16 -05:00
# Run tests
test_server_running
test_form_submission
sleep 2 # Allow time for async write
test_db_entry
2025-02-08 13:05:53 -05:00
2025-02-28 19:11:16 -05:00
echo "✅ All SQLite tests passed!"