Files
ginuerzh 43724a5c40 test: add http2 handler e2e suite and tighten host-mapper + idle-timeout tests
Add tests/e2e/http2_test.go covering the http2 handler/listener/connector/dialer
end-to-end through the canonical gost-as-client pattern (8 subtests: forward,
auth, bypass, probeResist/metadata, h2 stream multiplexing). Include
testdata/http2/{server,server_auth,server_bypass,server_proberesist,client,
client_auth}.yaml. Note that h2/h2c listeners pair with the tunnel handler
and only http2 listener pairs with handler http2 (reads r/w from metadata).

Tighten TestDNSHostMapper by pointing the handler at an unreachable upstream
so unmapped names fail at the exchanger, confirming the host-mapper path was
the sole reason mapped names resolved. Fix http_idle_timeout.py to speak HTTP
through the CONNECT tunnel rather than a raw ping, matching the echo backend.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-27 20:15:31 +08:00
..
2026-05-22 14:28:17 +08:00
2026-05-22 14:28:17 +08:00

End-to-End Tests

Integration tests that spin up real gost instances inside Docker containers and verify protocol behavior over the network.

Prerequisites

  • Docker (running daemon)
  • Go toolchain (for compiling the gost binary under test)

Running

From the repository root:

# Run all e2e tests
go test ./tests/e2e/ -v -timeout 10m

# Run a specific test suite
go test ./tests/e2e/ -v -run TestShadowsocksSuite -timeout 5m
go test ./tests/e2e/ -v -run TestParallelSelectorSuite -timeout 5m

# Use a pre-built gost binary (skips compilation)
go test ./tests/e2e/ -v -gost-bin /path/to/gost

Architecture

tests/e2e/
├── Dockerfile                  # Shared base image (Alpine + curl, python3, etc.)
├── main_test.go                # TestMain: compiles gost, creates Docker network
├── utils.go                    # Helpers: container lifecycle, config rendering
├── scripts/
│   ├── tcp_echo.py             # HTTP echo server (responds with "hello-gost")
│   └── udp_echo.py             # UDP echo server (reflects payloads)
├── testdata/                   # config files or data files for running cases
├── shadowsocks_test.go         # Shadowsocks protocol tests
└── parallel_selector_test.go   # Parallel node selector tests

How it works

  1. TestMain (main_test.go) compiles the gost binary from ../../cmd/gost (unless -gost-bin is provided) and creates a shared Docker network for all containers.
  2. Each test suite starts echo server containers (TCP/UDP), then launches separate gost containers for server and client roles.
  3. Client configs use Go template syntax ({{.ServerAddr}}) so the server address is injected at runtime.
  4. Tests verify end-to-end connectivity by sending traffic through the gost proxy chain and checking that the echo server responds correctly.

Tips

  • Increase -timeout for CI or slow networks. Container image builds on first run take extra time.
  • Use -gost-bin to avoid recompiling when iterating on tests locally.
  • Add -v to see container log output on failure.
  • RunGostContainer will wait for exposedPorts automatically, but it's not reliable for udp ports. So, you should check the readiness of udp ports inside cases.