Skip to content

Commit 6586764

Browse files
committed
Add integration tests
1 parent f2c83a6 commit 6586764

File tree

6 files changed

+745
-4
lines changed

6 files changed

+745
-4
lines changed

.github/workflows/naive-build.yml

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ jobs:
6262
if: steps.build-cache.outputs.cache-hit != 'true'
6363
run: ccache -s
6464
- name: Package
65-
run: go run ./cmd/build-naive --target=linux/${{ matrix.arch }} package --local
65+
run: |
66+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} package --local
67+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} package
6668
- name: Cache toolchain
6769
uses: actions/cache@v4
6870
with:
@@ -174,7 +176,9 @@ jobs:
174176
if: steps.build-cache.outputs.cache-hit != 'true'
175177
run: ccache -s
176178
- name: Package
177-
run: go run ./cmd/build-naive --target=${{ matrix.target }} package --local
179+
run: |
180+
go run ./cmd/build-naive --target=${{ matrix.target }} package --local
181+
go run ./cmd/build-naive --target=${{ matrix.target }} package
178182
- name: Build and run test binary
179183
if: matrix.target == 'darwin/arm64'
180184
run: |
@@ -313,7 +317,9 @@ jobs:
313317
if: steps.build-cache.outputs.cache-hit != 'true'
314318
run: ccache -s
315319
- name: Package
316-
run: go run ./cmd/build-naive --target=android/${{ matrix.arch }} package --local
320+
run: |
321+
go run ./cmd/build-naive --target=android/${{ matrix.arch }} package --local
322+
go run ./cmd/build-naive --target=android/${{ matrix.arch }} package
317323
- name: Setup Android NDK
318324
uses: nttld/setup-ndk@v1
319325
id: setup-ndk
@@ -379,7 +385,9 @@ jobs:
379385
if: steps.build-cache.outputs.cache-hit != 'true'
380386
run: ccache -s
381387
- name: Package
382-
run: go run ./cmd/build-naive --target=linux/${{ matrix.arch }} --libc=musl package --local
388+
run: |
389+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} --libc=musl package --local
390+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} --libc=musl package
383391
- name: Cache toolchain
384392
uses: actions/cache@v4
385393
with:
@@ -417,6 +425,139 @@ jobs:
417425
include/
418426
include_cgo.go
419427
428+
integration-test:
429+
if: github.event_name == 'push'
430+
needs: [linux, darwin, windows]
431+
strategy:
432+
fail-fast: false
433+
matrix:
434+
include:
435+
- name: linux-amd64-cgo
436+
os: ubuntu-22.04
437+
artifact: cronet-linux-amd64
438+
target: linux/amd64
439+
mode: cgo
440+
- name: linux-amd64-purego
441+
os: ubuntu-22.04
442+
artifact: cronet-linux-amd64
443+
target: linux/amd64
444+
mode: purego
445+
- name: darwin-arm64
446+
os: macos-15
447+
artifact: cronet-darwin-arm64
448+
target: darwin/arm64
449+
mode: cgo
450+
- name: windows-amd64
451+
os: windows-2022
452+
artifact: cronet-windows-amd64
453+
target: windows/amd64
454+
mode: purego
455+
runs-on: ${{ matrix.os }}
456+
steps:
457+
- uses: actions/checkout@v4
458+
with:
459+
submodules: 'recursive'
460+
461+
- uses: actions/setup-go@v5
462+
with:
463+
go-version: ^1.24
464+
465+
- name: Download artifact
466+
uses: actions/download-artifact@v4
467+
with:
468+
name: ${{ matrix.artifact }}
469+
path: .
470+
471+
- name: Get naiveproxy commit
472+
id: naive
473+
shell: bash
474+
run: echo "commit=$(git -C naiveproxy rev-parse HEAD)" >> $GITHUB_OUTPUT
475+
476+
- name: Get Chromium version
477+
id: chromium
478+
shell: bash
479+
run: echo "version=$(cat naiveproxy/CHROMIUM_VERSION)" >> $GITHUB_OUTPUT
480+
481+
# Linux: restore build cache and toolchain cache (needed for env command)
482+
- name: Restore build cache (Linux)
483+
if: runner.os == 'Linux'
484+
uses: actions/cache/restore@v4
485+
with:
486+
path: naiveproxy/src/out
487+
key: naive-build-${{ steps.naive.outputs.commit }}-${{ hashFiles('cmd/build-naive/cmd_build.go', 'cmd/build-naive/cmd.go') }}-linux-amd64
488+
489+
- name: Restore toolchain cache (Linux)
490+
if: runner.os == 'Linux'
491+
uses: actions/cache/restore@v4
492+
with:
493+
path: |
494+
naiveproxy/src/third_party/llvm-build
495+
naiveproxy/src/gn/out
496+
naiveproxy/src/chrome/build/pgo_profiles
497+
key: toolchain-linux-${{ steps.chromium.outputs.version }}
498+
499+
- name: Download toolchain (Linux)
500+
if: runner.os == 'Linux'
501+
run: go run ./cmd/build-naive --target=linux/amd64 download-toolchain
502+
503+
# Darwin: restore build cache (needed for env command)
504+
- name: Restore build cache (macOS)
505+
if: runner.os == 'macOS'
506+
uses: actions/cache/restore@v4
507+
with:
508+
path: naiveproxy/src/out
509+
key: naive-build-${{ steps.naive.outputs.commit }}-${{ hashFiles('cmd/build-naive/cmd_build.go', 'cmd/build-naive/cmd.go') }}-darwin-arm64
510+
511+
# Install iperf3
512+
- name: Install iperf3 (Linux)
513+
if: runner.os == 'Linux'
514+
run: |
515+
sudo apt update
516+
sudo apt install -y iperf3
517+
518+
- name: Install iperf3 (macOS)
519+
if: runner.os == 'macOS'
520+
run: brew install iperf3
521+
522+
- name: Install iperf3 (Windows)
523+
if: runner.os == 'Windows'
524+
run: choco install iperf3
525+
526+
# Generate package --local files
527+
- name: Package (non-Windows)
528+
if: runner.os != 'Windows'
529+
run: go run ./cmd/build-naive --target=${{ matrix.target }} package --local
530+
531+
# CGO mode tests
532+
- name: Run integration tests (CGO - Linux)
533+
if: matrix.mode == 'cgo' && runner.os == 'Linux'
534+
run: |
535+
eval $(go run ./cmd/build-naive --target=${{ matrix.target }} env --export)
536+
cd test && CGO_ENABLED=1 go test -v
537+
538+
- name: Run integration tests (CGO - macOS)
539+
if: matrix.mode == 'cgo' && runner.os == 'macOS'
540+
run: |
541+
eval $(go run ./cmd/build-naive --target=${{ matrix.target }} env --export)
542+
cd test && CGO_ENABLED=1 go test -v
543+
544+
# purego mode tests
545+
- name: Run integration tests (purego - Linux)
546+
if: matrix.mode == 'purego' && runner.os == 'Linux'
547+
working-directory: test
548+
run: |
549+
export LD_LIBRARY_PATH=$PWD/../lib/linux_amd64
550+
go test -tags with_purego -v
551+
552+
- name: Run integration tests (purego - Windows)
553+
if: matrix.mode == 'purego' && runner.os == 'Windows'
554+
working-directory: test
555+
shell: bash
556+
run: |
557+
# Add DLL directory to PATH for library loading
558+
export PATH="$PWD/../lib/windows_amd64:$PATH"
559+
go test -tags with_purego -v
560+
420561
publish:
421562
if: github.event_name == 'push'
422563
needs: [linux, linux-musl, darwin, windows, android]

test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

test/config/sing-box.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"inbounds": [
3+
{
4+
"type": "naive",
5+
"listen": "::",
6+
"listen_port": 10000,
7+
"users": [
8+
{
9+
"username": "test",
10+
"password": "test"
11+
}
12+
],
13+
"tls": {
14+
"enabled": true,
15+
"certificate_path": "/cert.pem",
16+
"key_path": "/key.pem"
17+
}
18+
}
19+
]
20+
}

test/go.mod

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module github.com/sagernet/cronet-go/test
2+
3+
go 1.24.0
4+
5+
require (
6+
github.com/sagernet/cronet-go v0.0.0
7+
github.com/sagernet/sing v0.7.13
8+
github.com/stretchr/testify v1.11.1
9+
go.uber.org/goleak v1.3.0
10+
)
11+
12+
require (
13+
github.com/davecgh/go-spew v1.1.1 // indirect
14+
github.com/ebitengine/purego v0.9.1 // indirect
15+
github.com/kr/pretty v0.3.1 // indirect
16+
github.com/pmezard/go-difflib v1.0.0 // indirect
17+
github.com/rogpeppe/go-internal v1.14.1 // indirect
18+
golang.org/x/sys v0.39.0 // indirect
19+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
20+
gopkg.in/yaml.v3 v3.0.1 // indirect
21+
)
22+
23+
replace github.com/sagernet/cronet-go => ../

test/go.sum

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A=
5+
github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
6+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
7+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
8+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
9+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
10+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
11+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
12+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
13+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
14+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
15+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
16+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
17+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
18+
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
19+
github.com/sagernet/sing v0.7.13 h1:XNYgd8e3cxMULs/LLJspdn/deHrnPWyrrglNHeCUAYM=
20+
github.com/sagernet/sing v0.7.13/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
21+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
22+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
23+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
24+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
25+
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
26+
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
27+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
28+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
29+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
30+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
31+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)