Testing Guide
Nantian Gateway’s testing system covers three layers: the control plane (Go), the data plane (Rust), and end-to-end integration tests. This page explains how to run each type of test, write new tests, and understand the CI pipeline.
Testing Overview
Section titled “Testing Overview”| Test Type | Language | Framework | Directory | Speed |
|---|---|---|---|---|
| Control plane unit tests | Go | testing + testify | gateway/internal/*/ | Fast (seconds) |
| Control plane integration tests | Go | envtest | gateway/internal/*/ | Medium (minutes) |
| Data plane unit tests | Rust | cargo test | dataplane/src/*/ | Fast (seconds) |
| Data plane integration tests | Rust | cargo test --test | dataplane/tests/ | Medium (minutes) |
| End-to-end tests | Go | Gateway API Conformance | gateway/test/e2e/ | Slow (tens of minutes) |
| Conformance tests | Go | Gateway API Conformance | gateway/test/conformance/ | Slow (tens of minutes) |
Control Plane Tests
Section titled “Control Plane Tests”Running Unit Tests
Section titled “Running Unit Tests”cd gateway
# Run all unit testsgo test ./internal/...
# Run tests for a specific packagego test ./internal/translator/...
# Run a specific test functiongo test -run TestTranslateHTTPRoute ./internal/translator/
# Run with verbose outputgo test -v ./internal/...
# Run with coverage reportgo test -coverprofile=coverage.out ./internal/...go tool cover -html=coverage.outRunning Integration Tests
Section titled “Running Integration Tests”The control plane’s integration tests use the controller-runtime envtest framework, which launches a real API Server binary locally:
# Run integration tests (requires envtest environment setup first)go test -tags=integration ./internal/controller/...
# First-time setup requires installing the envtest binarygo install sigs.k8s.io/controller-runtime/tools/setup-envtest@latestWriting Control Plane Tests
Section titled “Writing Control Plane Tests”Control plane tests follow standard Go community practices. Unit test files live in the same directory as source files, ending in _test.go.
package translator
import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" gwv1 "sigs.k8s.io/gateway-api/apis/v1")
func TestTranslateHTTPRoute(t *testing.T) { route := &gwv1.HTTPRoute{ // ... construct test data }
result, err := TranslateHTTPRoute(route)
require.NoError(t, err) assert.Equal(t, "expected-name", result.Name) assert.Len(t, result.Rules, 2)}Testing best practices:
- Use
testify/assertfor assertions,testify/requirefor precondition checks - Name test functions following the
Test<FunctionName>_<Scenario>format - Use table-driven tests to cover multiple input scenarios
- Mock external dependencies (Kubernetes Client, gRPC client, etc.)
Data Plane Tests
Section titled “Data Plane Tests”Running Unit Tests
Section titled “Running Unit Tests”cd dataplane
# Run all testscargo test
# Run tests for a specific modulecargo test --lib proxy::http
# Run a specific test functioncargo test test_http_route_match
# Show test outputcargo test -- --nocapture
# Run in parallel (defaults to CPU core count)cargo test -- --test-threads=4Running Integration Tests
Section titled “Running Integration Tests”Data plane integration tests are located in the dataplane/tests/ directory:
# Run all integration testscargo test --test integration
# Run a specific integration test filecargo test --test proxy_integrationWriting Data Plane Tests
Section titled “Writing Data Plane Tests”Rust tests are placed inside source files (unit tests) or in the tests/ directory (integration tests):
#[cfg(test)]mod tests { use super::*;
#[test] fn test_path_prefix_match() { let matcher = PathMatcher::new("PathPrefix", "/api/v1"); assert!(matcher.matches("/api/v1/users")); assert!(!matcher.matches("/other/path")); }
#[tokio::test] async fn test_http_route_resolution() { let route = build_test_route(); let backend = resolve_backend(&route, &build_test_request()).await; assert!(backend.is_some()); }}Testing best practices:
- Place unit tests in
#[cfg(test)] mod tests - Use
#[tokio::test]attribute for async tests - Use
assert!,assert_eq!,assert_ne!macros for assertions - For complex scenarios, use
rstestortest-casecrates for parameterized tests
End-to-End Tests
Section titled “End-to-End Tests”End-to-end tests verify that the control plane and data plane work together correctly in a real Kubernetes cluster:
cd gateway
# Run end-to-end tests (requires a Kind cluster)make test-e2e
# Run manuallygo test -tags=e2e ./test/e2e/... -vThe end-to-end test workflow:
- Install Nantian Gateway in a Kind cluster
- Deploy sample backend services
- Create Gateway and HTTPRoute resources
- Send requests to the gateway via port forwarding
- Verify response content and status codes
Gateway API Conformance Tests
Section titled “Gateway API Conformance Tests”Nantian Gateway runs the official Gateway API conformance test suite to verify the implementation’s compliance with the specification:
cd gateway
# Run conformance testsmake test-conformance
# Run manuallygo test -tags=conformance ./test/conformance/... -vConformance tests produce a report listing all passing and failing features. This report serves as the basis for the project’s declared feature support.
Code Quality Checks
Section titled “Code Quality Checks”Go Code
Section titled “Go Code”cd gateway
# Code formattinggofmt -w .
# Lint checksgolangci-lint run ./...
# Static analysisgo vet ./...Rust Code
Section titled “Rust Code”cd dataplane
# Code formattingcargo fmt
# Lint checkscargo clippy -- -D warnings
# Check for unused dependenciescargo udepsProtobuf
Section titled “Protobuf”cd proto
# Format checkbuf format -d
# Lint checkbuf lintCI Pipeline
Section titled “CI Pipeline”Nantian Gateway uses GitHub Actions for continuous integration. Each PR triggers the following checks:
| Check | Description | Trigger Condition |
|---|---|---|
| Go Unit Tests | Control plane unit tests | All PRs |
| Go Integration Tests | Control plane integration tests | All PRs |
| Rust Unit Tests | Data plane unit tests | All PRs |
| Rust Integration Tests | Data plane integration tests | All PRs |
| Go Lint | golangci-lint | All PRs |
| Rust Lint | clippy + fmt | All PRs |
| Proto Lint | buf lint | Proto changes |
| E2E Tests | End-to-end tests | Before merging to main |
| Conformance Tests | Gateway API conformance tests | Before merging to main |
CI configuration files are located in the .github/workflows/ directory.
Test Coverage
Section titled “Test Coverage”The project uses Codecov to track test coverage:
# Go coveragecd gatewaygo test -coverprofile=coverage.out ./internal/...go tool cover -func=coverage.out
# Rust coverage (requires cargo-tarpaulin)cd dataplanecargo install cargo-tarpaulincargo tarpaulin --out HtmlCoverage reports are automatically uploaded to Codecov as part of CI. The project doesn’t enforce a hard coverage threshold, but new code is encouraged to include corresponding test cases.
Next Steps
Section titled “Next Steps”- See Release Process to learn about version release rules
- See Development Setup to learn about local environment setup
- See Contributing Overview to understand the full contribution workflow