test: add integration smoke test script
This commit is contained in:
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${PROXY_URL:-http://localhost:8080}"
|
||||
API_KEY="${UPSTREAM_API_KEY:-test-key}"
|
||||
|
||||
echo "=== Smoke testing openai-proxy at $BASE_URL ==="
|
||||
|
||||
echo ""
|
||||
echo "1. GET /health"
|
||||
HEALTH=$(curl -sf "$BASE_URL/health")
|
||||
echo " Response: $HEALTH"
|
||||
echo "$HEALTH" | grep -q '"ok"' && echo " PASS" || { echo " FAIL"; exit 1; }
|
||||
|
||||
echo ""
|
||||
echo "2. POST /v1/chat/completions (non-streaming)"
|
||||
RESP=$(curl -sf "$BASE_URL/v1/chat/completions" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-d '{
|
||||
"model": "gpt-4o-mini",
|
||||
"messages": [
|
||||
{"role": "system", "content": "You are a concise assistant."},
|
||||
{"role": "user", "content": "Reply with exactly: pong"}
|
||||
],
|
||||
"max_tokens": 10
|
||||
}')
|
||||
echo " Response: $RESP"
|
||||
echo "$RESP" | grep -q '"choices"' && echo " PASS" || { echo " FAIL"; exit 1; }
|
||||
|
||||
echo ""
|
||||
echo "3. POST /v1/chat/completions (streaming)"
|
||||
STREAM_RESP=$(curl -sf "$BASE_URL/v1/chat/completions" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-d '{
|
||||
"model": "gpt-4o-mini",
|
||||
"messages": [{"role": "user", "content": "Say hi"}],
|
||||
"stream": true,
|
||||
"max_tokens": 10
|
||||
}')
|
||||
echo " First bytes: $(echo "$STREAM_RESP" | head -c 100)"
|
||||
echo "$STREAM_RESP" | grep -q 'data:' && echo " PASS" || { echo " FAIL"; exit 1; }
|
||||
|
||||
echo ""
|
||||
echo "4. GET /v1/models"
|
||||
MODELS=$(curl -sf "$BASE_URL/v1/models" \
|
||||
-H "Authorization: Bearer $API_KEY")
|
||||
echo " Response (first 200 chars): $(echo "$MODELS" | head -c 200)"
|
||||
echo "$MODELS" | grep -q '"data"' && echo " PASS" || { echo " FAIL"; exit 1; }
|
||||
|
||||
echo ""
|
||||
echo "5. POST /v1/chat/completions (with tools)"
|
||||
TOOL_RESP=$(curl -sf "$BASE_URL/v1/chat/completions" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-d '{
|
||||
"model": "gpt-4o-mini",
|
||||
"messages": [{"role": "user", "content": "What is the weather in NYC?"}],
|
||||
"tools": [{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"description": "Get current weather",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {"city": {"type": "string"}},
|
||||
"required": ["city"]
|
||||
}
|
||||
}
|
||||
}],
|
||||
"tool_choice": "auto",
|
||||
"max_tokens": 100
|
||||
}')
|
||||
echo " Response: $(echo "$TOOL_RESP" | head -c 300)"
|
||||
echo "$TOOL_RESP" | grep -q '"choices"' && echo " PASS" || { echo " FAIL"; exit 1; }
|
||||
|
||||
echo ""
|
||||
echo "=== All smoke tests PASSED ==="
|
||||
Reference in New Issue
Block a user