Skip to content

Commit 12ce39a

Browse files
committed
Add integration tests
1 parent f2c83a6 commit 12ce39a

File tree

6 files changed

+730
-0
lines changed

6 files changed

+730
-0
lines changed

.github/workflows/naive-build.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,140 @@ jobs:
417417
include/
418418
include_cgo.go
419419
420+
integration-test:
421+
if: github.event_name == 'push'
422+
needs: [linux, darwin, windows]
423+
strategy:
424+
fail-fast: false
425+
matrix:
426+
include:
427+
- name: linux-amd64-cgo
428+
os: ubuntu-22.04
429+
artifact: cronet-linux-amd64
430+
target: linux/amd64
431+
mode: cgo
432+
- name: linux-amd64-purego
433+
os: ubuntu-22.04
434+
artifact: cronet-linux-amd64
435+
target: linux/amd64
436+
mode: purego
437+
- name: darwin-arm64
438+
os: macos-15
439+
artifact: cronet-darwin-arm64
440+
target: darwin/arm64
441+
mode: cgo
442+
- name: windows-amd64
443+
os: windows-2022
444+
artifact: cronet-windows-amd64
445+
target: windows/amd64
446+
mode: purego
447+
runs-on: ${{ matrix.os }}
448+
steps:
449+
- uses: actions/checkout@v4
450+
with:
451+
submodules: 'recursive'
452+
453+
- uses: actions/setup-go@v5
454+
with:
455+
go-version: ^1.24
456+
457+
- name: Download artifact
458+
uses: actions/download-artifact@v4
459+
with:
460+
name: ${{ matrix.artifact }}
461+
path: .
462+
463+
- name: Get naiveproxy commit
464+
id: naive
465+
shell: bash
466+
run: echo "commit=$(git -C naiveproxy rev-parse HEAD)" >> $GITHUB_OUTPUT
467+
468+
- name: Get Chromium version
469+
id: chromium
470+
shell: bash
471+
run: echo "version=$(cat naiveproxy/CHROMIUM_VERSION)" >> $GITHUB_OUTPUT
472+
473+
# Linux: restore build cache and toolchain cache (needed for env command)
474+
- name: Restore build cache (Linux)
475+
if: runner.os == 'Linux'
476+
uses: actions/cache/restore@v4
477+
with:
478+
path: naiveproxy/src/out
479+
key: naive-build-${{ steps.naive.outputs.commit }}-${{ hashFiles('cmd/build-naive/cmd_build.go', 'cmd/build-naive/cmd.go') }}-linux-amd64
480+
481+
- name: Restore toolchain cache (Linux)
482+
if: runner.os == 'Linux'
483+
uses: actions/cache/restore@v4
484+
with:
485+
path: |
486+
naiveproxy/src/third_party/llvm-build
487+
naiveproxy/src/gn/out
488+
naiveproxy/src/chrome/build/pgo_profiles
489+
key: toolchain-linux-${{ steps.chromium.outputs.version }}
490+
491+
- name: Download toolchain (Linux)
492+
if: runner.os == 'Linux'
493+
run: go run ./cmd/build-naive --target=linux/amd64 download-toolchain
494+
495+
# Darwin: restore build cache (needed for env command)
496+
- name: Restore build cache (macOS)
497+
if: runner.os == 'macOS'
498+
uses: actions/cache/restore@v4
499+
with:
500+
path: naiveproxy/src/out
501+
key: naive-build-${{ steps.naive.outputs.commit }}-${{ hashFiles('cmd/build-naive/cmd_build.go', 'cmd/build-naive/cmd.go') }}-darwin-arm64
502+
503+
# Install iperf3
504+
- name: Install iperf3 (Linux)
505+
if: runner.os == 'Linux'
506+
run: |
507+
sudo apt update
508+
sudo apt install -y iperf3
509+
510+
- name: Install iperf3 (macOS)
511+
if: runner.os == 'macOS'
512+
run: brew install iperf3
513+
514+
- name: Install iperf3 (Windows)
515+
if: runner.os == 'Windows'
516+
run: choco install iperf3
517+
518+
# Generate package --local files
519+
- name: Package (non-Windows)
520+
if: runner.os != 'Windows'
521+
run: go run ./cmd/build-naive --target=${{ matrix.target }} package --local
522+
523+
# CGO mode tests
524+
- name: Run integration tests (CGO - Linux)
525+
if: matrix.mode == 'cgo' && runner.os == 'Linux'
526+
working-directory: test
527+
run: |
528+
eval $(go run ../cmd/build-naive --target=${{ matrix.target }} env --export)
529+
CGO_ENABLED=1 go test -v
530+
531+
- name: Run integration tests (CGO - macOS)
532+
if: matrix.mode == 'cgo' && runner.os == 'macOS'
533+
working-directory: test
534+
run: |
535+
eval $(go run ../cmd/build-naive --target=${{ matrix.target }} env --export)
536+
CGO_ENABLED=1 go test -v
537+
538+
# purego mode tests
539+
- name: Run integration tests (purego - Linux)
540+
if: matrix.mode == 'purego' && runner.os == 'Linux'
541+
working-directory: test
542+
run: |
543+
export LD_LIBRARY_PATH=$PWD/../lib/linux_amd64
544+
go test -tags with_purego -v
545+
546+
- name: Run integration tests (purego - Windows)
547+
if: matrix.mode == 'purego' && runner.os == 'Windows'
548+
working-directory: test
549+
shell: bash
550+
run: |
551+
cp ../lib/windows_amd64/libcronet.dll .
552+
go test -tags with_purego -v
553+
420554
publish:
421555
if: github.event_name == 'push'
422556
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)