Skip to content

Commit ef66cda

Browse files
committed
ci: add test.yml
Signed-off-by: Xin Liu <[email protected]>
1 parent 4edcb59 commit ef66cda

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

.github/workflows/test.yml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
- main
8+
- release-*
9+
- feat-*
10+
- ci-*
11+
- refactor-*
12+
- fix-*
13+
- test-*
14+
paths:
15+
- ".github/workflows/test.yml"
16+
- "**/Cargo.toml"
17+
- "**/*.rs"
18+
- "**/*.sh"
19+
- "**/*.sql"
20+
- "tests/*.hurl"
21+
pull_request:
22+
branches:
23+
- dev
24+
- main
25+
types: [opened, synchronize, reopened]
26+
paths:
27+
- ".github/workflows/**"
28+
- "**/Cargo.toml"
29+
- "**/*.rs"
30+
- "**/*.sh"
31+
- "**/*.sql"
32+
- "tests/**"
33+
34+
env:
35+
CARGO_TERM_COLOR: always
36+
37+
jobs:
38+
# =============================================================================
39+
# Hurl API Tests (Fast, HTTP/HTTPS + WebSocket handshake)
40+
# =============================================================================
41+
hurl-tests:
42+
name: Hurl API Tests
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
49+
- name: Install Rust toolchain
50+
uses: dtolnay/rust-toolchain@stable
51+
with:
52+
toolchain: 1.90.0
53+
54+
- name: Cache cargo dependencies
55+
uses: actions/cache@v4
56+
with:
57+
path: |
58+
~/.cargo/registry
59+
~/.cargo/git
60+
target
61+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
62+
restore-keys: |
63+
${{ runner.os }}-cargo-
64+
65+
- name: Install Hurl
66+
run: |
67+
HURL_VERSION=5.0.1
68+
curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/${HURL_VERSION}/hurl_${HURL_VERSION}_amd64.deb
69+
sudo dpkg -i hurl_${HURL_VERSION}_amd64.deb
70+
hurl --version
71+
72+
- name: Build project
73+
run: cargo build --release --verbose
74+
75+
- name: Initialize test database
76+
run: |
77+
chmod +x init_db.sh
78+
./init_db.sh
79+
sqlite3 sessions.db < tests/fixtures.sql
80+
echo "✅ Test database initialized"
81+
82+
- name: Start ss-proxy server in background
83+
run: |
84+
./target/release/ss-proxy --port 8080 --log-level debug &
85+
SERVER_PID=$!
86+
echo "SERVER_PID=$SERVER_PID" >> $GITHUB_ENV
87+
echo "🚀 Server started with PID: $SERVER_PID"
88+
sleep 3
89+
90+
- name: Wait for server to be ready
91+
run: |
92+
echo "⏳ Waiting for server to be ready..."
93+
for i in {1..30}; do
94+
if curl -f http://localhost:8080/health > /dev/null 2>&1; then
95+
echo "✅ Server is ready!"
96+
exit 0
97+
fi
98+
echo "Attempt $i: Server not ready yet..."
99+
sleep 1
100+
done
101+
echo "❌ Server failed to start"
102+
exit 1
103+
104+
- name: Run HTTP/HTTPS tests with Hurl
105+
run: |
106+
echo "🧪 Running HTTP/HTTPS tests..."
107+
hurl --test --color tests/http.hurl
108+
109+
- name: Run WebSocket handshake tests with Hurl
110+
run: |
111+
echo "🧪 Running WebSocket tests..."
112+
hurl --test --color tests/websocket.hurl
113+
114+
- name: Stop server
115+
if: always()
116+
run: |
117+
if [ ! -z "$SERVER_PID" ]; then
118+
echo "🛑 Stopping server (PID: $SERVER_PID)"
119+
kill $SERVER_PID || true
120+
fi
121+
122+
# =============================================================================
123+
# Rust Integration Tests (Comprehensive, includes WebSocket message exchange)
124+
# =============================================================================
125+
rust-integration-tests:
126+
name: Rust Integration Tests
127+
runs-on: ubuntu-latest
128+
129+
steps:
130+
- name: Checkout code
131+
uses: actions/checkout@v4
132+
133+
- name: Install Rust toolchain
134+
uses: dtolnay/rust-toolchain@stable
135+
with:
136+
toolchain: 1.90.0
137+
138+
- name: Cache cargo dependencies
139+
uses: actions/cache@v4
140+
with:
141+
path: |
142+
~/.cargo/registry
143+
~/.cargo/git
144+
target
145+
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
146+
restore-keys: |
147+
${{ runner.os }}-cargo-test-
148+
149+
- name: Run integration tests
150+
run: |
151+
echo "🧪 Running Rust integration tests..."
152+
cargo test --test integration --release -- --test-threads=1 --nocapture
153+
env:
154+
RUST_LOG: debug
155+
156+
# =============================================================================
157+
# Summary Job (depends on all test jobs)
158+
# =============================================================================
159+
test-summary:
160+
name: Test Summary
161+
runs-on: ubuntu-latest
162+
needs: [hurl-tests, rust-integration-tests]
163+
if: always()
164+
165+
steps:
166+
- name: Check test results
167+
run: |
168+
if [ "${{ needs.hurl-tests.result }}" != "success" ] || [ "${{ needs.rust-integration-tests.result }}" != "success" ]; then
169+
echo "❌ Some tests failed"
170+
exit 1
171+
else
172+
echo "✅ All tests passed!"
173+
fi
174+
175+

0 commit comments

Comments
 (0)