Skip to content

Commit 4edcb59

Browse files
committed
feat: add integration test infrastructure
Implement dual-layer testing strategy: - Hurl tests for fast HTTP/HTTPS and WebSocket API testing - Rust integration tests for comprehensive coverage - Support `TEST_PORT` env var for flexible port configuration - Add test fixtures and local test runner script - Add comprehensive test documentation Test coverage: HTTP methods, WebSocket messages, error handling Signed-off-by: Xin Liu <[email protected]>
1 parent 38506ba commit 4edcb59

File tree

8 files changed

+902
-0
lines changed

8 files changed

+902
-0
lines changed

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ tower-http = { version = "0.6", features = ["trace", "cors"] }
3636
# Logging
3737
tracing = "0.1"
3838
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
39+
40+
[dev-dependencies]
41+
# Integration testing dependencies
42+
tokio-test = "0.4"

run_tests.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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

Comments
 (0)