AtlatestRepositorysigil-http
sigil-http / tree / testtest-integration.sh
1
#!/usr/bin/env bash2
# Integration tests for (sigil http server) Phase 2 features3
#4
# Tests:5
# - GET requests6
# - POST requests with body7
# - Request body reading with Content-Length9
set -e11
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"12
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"13
SERVER_LOG="/tmp/sigil-http-test.log"14
PORT=809916
# Ensure we're in the project root17
cd "$PROJECT_ROOT"19
# Kill any existing test server20
pkill -f "integration-server" 2>/dev/null || true21
sleep 123
# Compile the test server if needed24
echo "Compiling test server..."25
./build/bin/sgl-boot --compile packages/sigil-http/test/integration-server.sgl \26
packages/sigil-http/lib/test/integration-server.sgb28
# Start server on a different port for testing29
echo "Starting test server on port $PORT..."30
./build/bin/sigil -L packages/sigil-http/lib packages/sigil-http/lib/test/integration-server.sgb > "$SERVER_LOG" 2>&1 &31
SERVER_PID=$!33
# Wait for server to start34
sleep 336
# Check if server is running37
if ! kill -0 $SERVER_PID 2>/dev/null; then38
echo "FAIL: Server failed to start"39
cat "$SERVER_LOG"40
exit 141
fi43
FAILED=045
run_test() {46
local name="$1"47
local expected="$2"48
local actual="$3"50
if [ "$expected" = "$actual" ]; then51
echo "PASS: $name"52
else53
echo "FAIL: $name"54
echo " Expected: $expected"55
echo " Actual: $actual"56
FAILED=157
fi58
}60
# Test 1: Simple GET request61
echo ""62
echo "=== Test 1: Simple GET /hello ==="63
RESULT=$(curl -s --max-time 5 http://localhost:$PORT/hello)64
run_test "GET /hello returns 'Hello, World!'" "Hello, World!" "$RESULT"66
# Test 2: GET returns 404 for unknown path67
echo ""68
echo "=== Test 2: GET unknown path returns 404 ==="69
RESULT=$(curl -s --max-time 5 -o /dev/null -w "%{http_code}" http://localhost:$PORT/unknown)70
run_test "GET /unknown returns 404" "404" "$RESULT"72
# Test 3: POST with body73
echo ""74
echo "=== Test 3: POST with body ==="75
RESULT=$(curl -s --max-time 5 -X POST -d "test body data" http://localhost:$PORT/echo-body)76
run_test "POST /echo-body echoes body" "test body data" "$RESULT"78
# Test 4: POST without body79
echo ""80
echo "=== Test 4: POST without body ==="81
RESULT=$(curl -s --max-time 5 -X POST http://localhost:$PORT/echo-body)82
run_test "POST /echo-body without body" "(no body)" "$RESULT"84
# Test 5: POST with larger body85
echo ""86
echo "=== Test 5: POST with larger body ==="87
LARGE_BODY="This is a larger body with multiple lines.88
Line 2 of the body.89
Line 3 with some special chars: <>\"'&90
End of body."91
RESULT=$(curl -s --max-time 5 -X POST -d "$LARGE_BODY" http://localhost:$PORT/echo-body)92
run_test "POST /echo-body with large body" "$LARGE_BODY" "$RESULT"94
# Cleanup95
echo ""96
echo "Cleaning up..."97
kill $SERVER_PID 2>/dev/null || true98
wait $SERVER_PID 2>/dev/null || true100
# Summary101
echo ""102
if [ $FAILED -eq 0 ]; then103
echo "All tests passed!"104
exit 0105
else106
echo "Some tests failed!"107
echo ""108
echo "Server log:"109
cat "$SERVER_LOG"110
exit 1111
fi