Skip to content

Commit 5c27ba3

Browse files
authored
CI: add tun2socks e2e tests (#510)
1 parent ed41b97 commit 5c27ba3

File tree

2 files changed

+189
-13
lines changed

2 files changed

+189
-13
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ jobs:
2525
check-latest: true
2626
go-version-file: 'go.mod'
2727

28-
- name: Cache go module
29-
uses: actions/cache@v4
30-
with:
31-
path: |
32-
~/go/pkg/mod
33-
~/.cache/go-build
34-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
35-
restore-keys: |
36-
${{ runner.os }}-go-
37-
3828
- name: Set prerelease flag
3929
if: startsWith(github.ref, 'refs/tags/')
4030
id: pre

.github/workflows/test.yml

Lines changed: 189 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,26 @@ on:
1111
pull_request:
1212

1313
jobs:
14-
build-test:
14+
unit:
15+
name: Unit Test
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v5
20+
21+
- name: Setup Go
22+
uses: actions/setup-go@v6
23+
with:
24+
check-latest: true
25+
go-version-file: 'go.mod'
26+
27+
- name: Run unit test
28+
run: |
29+
go test ./...
30+
31+
build:
1532
name: Build Test
33+
needs: unit
1634
runs-on: ubuntu-latest
1735
steps:
1836
- name: Checkout code
@@ -26,6 +44,174 @@ jobs:
2644
check-latest: true
2745
go-version-file: 'go.mod'
2846

29-
- name: Run test
47+
- name: Run build test
48+
run: make -j all
49+
50+
e2e:
51+
name: E2E Test (${{ matrix.protocol }})
52+
needs: build
53+
runs-on: ubuntu-latest
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
include:
58+
- protocol: HTTP
59+
image: gogost/gost:latest
60+
args: -L "http://:8080"
61+
proxy: http://192.168.1.2:8080
62+
udp: false
63+
- protocol: SOCKSv4
64+
image: gogost/gost:latest
65+
args: -L "socks4://:1080"
66+
proxy: socks4://192.168.1.2:1080
67+
udp: false
68+
- protocol: SOCKSv5
69+
image: gogost/gost:latest
70+
args: -L "socks5://:1080?udp=true"
71+
proxy: socks5://192.168.1.2:1080
72+
udp: true
73+
- protocol: Relay
74+
image: gogost/gost:latest
75+
args: -L "relay://:8420"
76+
proxy: relay://192.168.1.2:8420
77+
udp: true
78+
- protocol: Shadowsocks
79+
image: ghcr.io/shadowsocks/ssserver-rust:latest
80+
args: ssserver -s 0.0.0.0:8388 -k pass -m aes-128-gcm -U -v
81+
proxy: ss://aes-128-gcm:[email protected]:8388
82+
udp: true
83+
env:
84+
TUN_IF: tun0
85+
RESTAPI_PORT: 8080
86+
SUBNET_NAME: e2e-net
87+
SUBNET_PREFIX: 192.168.1
88+
APP_IPERF: iperf
89+
APP_PROXY: proxy
90+
APP_TESTER: tester
91+
APP_TUN2SOCKS: tun2socks
92+
steps:
93+
- name: Checkout code
94+
uses: actions/checkout@v5
95+
96+
- name: Create CI Dockerfile
3097
run: |
31-
go test ./...
98+
cp Dockerfile Dockerfile.ci
99+
cat >> Dockerfile.ci <<EOF
100+
RUN apk add --update --no-cache \
101+
bind-tools curl iperf3
102+
EOF
103+
104+
- name: Build CI image
105+
run: docker build -f Dockerfile.ci -t tun2socks:ci .
106+
107+
- name: Create test network
108+
run: |
109+
docker network create \
110+
--driver bridge \
111+
--subnet "${SUBNET_PREFIX}.0/24" \
112+
"${SUBNET_NAME}"
113+
114+
- name: Start proxy
115+
run: |
116+
docker run -d \
117+
--name "${APP_PROXY}" \
118+
--network "${SUBNET_NAME}" \
119+
--ip "${SUBNET_PREFIX}.2" \
120+
${{ matrix.image }} ${{ matrix.args }}
121+
122+
- name: Start iperf
123+
run: |
124+
docker run -d \
125+
--name "${APP_IPERF}" \
126+
--network "${SUBNET_NAME}" \
127+
--ip "${SUBNET_PREFIX}.3" \
128+
networkstatic/iperf3:latest \
129+
-s --logfile /dev/null
130+
131+
- name: Start tun2socks
132+
env:
133+
PROXY: ${{ matrix.proxy }}
134+
run: |
135+
docker run -d \
136+
--name "${APP_TUN2SOCKS}" \
137+
--cap-add=NET_ADMIN \
138+
--device /dev/net/tun:/dev/net/tun \
139+
--network "${SUBNET_NAME}" \
140+
--ip "${SUBNET_PREFIX}.4" \
141+
-e TUN="${TUN_IF}" \
142+
-e PROXY="${PROXY}" \
143+
-e RESTAPI=":${RESTAPI_PORT}" \
144+
-p "${RESTAPI_PORT}:${RESTAPI_PORT}" \
145+
tun2socks:ci
146+
147+
- name: Start tester
148+
run: |
149+
docker run -d \
150+
--name "${APP_TESTER}" \
151+
--cap-add=NET_ADMIN \
152+
--network "${SUBNET_NAME}" \
153+
--entrypoint sh \
154+
tun2socks:ci \
155+
-c "sleep infinite"
156+
157+
- name: Set up tester
158+
run: docker exec "${APP_TESTER}" ip route add 1.1.1.1 via "${SUBNET_PREFIX}.4"
159+
160+
- name: Check readiness
161+
run: |
162+
for i in $(seq 1 10); do
163+
if curl -fsS --max-time 2 -o /dev/null "http://localhost:${RESTAPI_PORT}"; then
164+
exit 0
165+
fi
166+
sleep 1
167+
done
168+
exit 1
169+
170+
- name: Test TCP via HTTP
171+
run: docker exec "${APP_TUN2SOCKS}" curl -fsS -v --max-time 10 ipinfo.io
172+
173+
- name: Test UDP via DNS
174+
if: ${{ matrix.udp }}
175+
run: docker exec "${APP_TUN2SOCKS}" dig @8.8.8.8 www.google.com +tries=2
176+
177+
- name: Test UDP via QUIC
178+
if: ${{ matrix.udp }}
179+
run: |
180+
docker exec "${APP_TUN2SOCKS}" curl -fsS -v --max-time 10 -o /dev/null \
181+
--http3-only https://cloudflare-quic.com
182+
183+
- name: Test upload speed via iPerf
184+
run: |
185+
docker exec "${APP_TUN2SOCKS}" iperf3 --bind-dev "${TUN_IF}" \
186+
--connect-timeout 2000 -c "${SUBNET_PREFIX}.3"
187+
188+
- name: Test download speed via iPerf
189+
run: |
190+
docker exec "${APP_TUN2SOCKS}" iperf3 --bind-dev "${TUN_IF}" \
191+
--connect-timeout 2000 -c "${SUBNET_PREFIX}.3" -R
192+
193+
- name: Test routing (TCP)
194+
run: docker exec "${APP_TESTER}" curl -fsS -v --max-time 10 -o /dev/null 1.1.1.1
195+
196+
- name: Test routing (UDP)
197+
if: ${{ matrix.udp }}
198+
run: docker exec "${APP_TESTER}" dig @1.1.1.1 www.cloudflare.com +tries=2
199+
200+
- name: Dump proxy logs
201+
if: always()
202+
run: |
203+
docker logs "${APP_PROXY}" || true
204+
205+
- name: Dump tun2socks logs
206+
if: always()
207+
run: |
208+
docker logs "${APP_TUN2SOCKS}" || true
209+
210+
- name: Cleanup
211+
if: always()
212+
run: |
213+
docker rm -f "${APP_TUN2SOCKS}" || true
214+
docker rm -f "${APP_TESTER}" || true
215+
docker rm -f "${APP_IPERF}" || true
216+
docker rm -f "${APP_PROXY}" || true
217+
docker network rm "${SUBNET_NAME}" || true

0 commit comments

Comments
 (0)