|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Test helper script for local testing |
| 4 | +# Run integration tests locally before pushing to GitHub |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +echo "🧪 SS-Proxy Local Test Suite" |
| 9 | +echo "================================" |
| 10 | + |
| 11 | +# Colors for output |
| 12 | +RED='\033[0;31m' |
| 13 | +GREEN='\033[0;32m' |
| 14 | +YELLOW='\033[1;33m' |
| 15 | +NC='\033[0m' # No Color |
| 16 | + |
| 17 | +# Check if Hurl is installed |
| 18 | +if ! command -v hurl &> /dev/null; then |
| 19 | + echo -e "${YELLOW}⚠️ Hurl not found. Installing...${NC}" |
| 20 | + if [[ "$OSTYPE" == "darwin"* ]]; then |
| 21 | + brew install hurl |
| 22 | + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then |
| 23 | + echo "Please install Hurl from: https://hurl.dev/docs/installation.html" |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +fi |
| 27 | + |
| 28 | +# Clean up any existing server process |
| 29 | +cleanup() { |
| 30 | + if [ ! -z "$SERVER_PID" ]; then |
| 31 | + echo -e "${YELLOW}🛑 Stopping server (PID: $SERVER_PID)${NC}" |
| 32 | + kill $SERVER_PID 2>/dev/null || true |
| 33 | + wait $SERVER_PID 2>/dev/null || true |
| 34 | + fi |
| 35 | + rm -f /tmp/ss-proxy.pid |
| 36 | +} |
| 37 | + |
| 38 | +trap cleanup EXIT |
| 39 | + |
| 40 | +echo "" |
| 41 | +echo "📦 Step 1: Building project..." |
| 42 | +cargo build --release |
| 43 | + |
| 44 | +echo "" |
| 45 | +echo "🗄️ Step 2: Initializing test database..." |
| 46 | +./init_db.sh |
| 47 | +sqlite3 sessions.db < tests/fixtures.sql |
| 48 | +echo -e "${GREEN}✅ Database initialized${NC}" |
| 49 | + |
| 50 | +echo "" |
| 51 | +echo "🚀 Step 3: Starting server..." |
| 52 | +./target/release/ss-proxy --port 8080 --log-level debug & |
| 53 | +SERVER_PID=$! |
| 54 | +echo $SERVER_PID > /tmp/ss-proxy.pid |
| 55 | +echo -e "${GREEN}Server started with PID: $SERVER_PID${NC}" |
| 56 | + |
| 57 | +# Wait for server to be ready |
| 58 | +echo "" |
| 59 | +echo "⏳ Waiting for server to be ready..." |
| 60 | +for i in {1..30}; do |
| 61 | + if curl -f http://localhost:8080/health > /dev/null 2>&1; then |
| 62 | + echo -e "${GREEN}✅ Server is ready!${NC}" |
| 63 | + break |
| 64 | + fi |
| 65 | + if [ $i -eq 30 ]; then |
| 66 | + echo -e "${RED}❌ Server failed to start${NC}" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + sleep 1 |
| 70 | +done |
| 71 | + |
| 72 | +echo "" |
| 73 | +echo "🧪 Step 4: Running Hurl tests..." |
| 74 | +echo "--------------------------------" |
| 75 | + |
| 76 | +echo "" |
| 77 | +echo "Testing HTTP/HTTPS endpoints..." |
| 78 | +if hurl --test --color tests/http.hurl; then |
| 79 | + echo -e "${GREEN}✅ HTTP tests passed${NC}" |
| 80 | +else |
| 81 | + echo -e "${RED}❌ HTTP tests failed${NC}" |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | + |
| 85 | +echo "" |
| 86 | +echo "Testing WebSocket endpoints..." |
| 87 | +if hurl --test --color tests/websocket.hurl; then |
| 88 | + echo -e "${GREEN}✅ WebSocket tests passed${NC}" |
| 89 | +else |
| 90 | + echo -e "${RED}❌ WebSocket tests failed${NC}" |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | + |
| 94 | +echo "" |
| 95 | +echo "🛑 Step 5: Stopping server for Rust integration tests..." |
| 96 | +cleanup |
| 97 | +sleep 2 |
| 98 | + |
| 99 | +echo "" |
| 100 | +echo "🦀 Step 6: Running Rust integration tests..." |
| 101 | +echo "---------------------------------------------" |
| 102 | +if cargo test --test integration --release -- --test-threads=1 --nocapture; then |
| 103 | + echo -e "${GREEN}✅ Rust integration tests passed${NC}" |
| 104 | +else |
| 105 | + echo -e "${RED}❌ Rust integration tests failed${NC}" |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | + |
| 109 | +echo "" |
| 110 | +echo "================================" |
| 111 | +echo -e "${GREEN}🎉 All tests passed!${NC}" |
| 112 | +echo "================================" |
0 commit comments