|
2 | 2 |
|
3 | 3 | // Package e2e provides end-to-end tests for the a7 CLI. |
4 | 4 | // These tests run against a real API7 Enterprise Edition instance and require |
5 | | -// the following environment to be available: |
| 5 | +// the following environment variables: |
6 | 6 | // |
7 | | -// - API7 EE Dashboard API at A7_ADMIN_URL (default: https://127.0.0.1:7443) |
8 | | -// - API7 EE Gateway at A7_GATEWAY_URL (default: http://127.0.0.1:9080) |
9 | | -// - httpbin at HTTPBIN_URL (default: http://127.0.0.1:8080) |
| 7 | +// - A7_ADMIN_URL: API7 EE Dashboard/control-plane URL (required) |
| 8 | +// - A7_TOKEN: API7 EE access token (required) |
| 9 | +// - A7_GATEWAY_GROUP: Gateway group name (default: "default") |
| 10 | +// - A7_GATEWAY_URL: Gateway data-plane URL (optional — gateway traffic tests skipped if empty) |
| 11 | +// - HTTPBIN_URL: httpbin URL (optional — traffic forwarding tests skipped if empty) |
10 | 12 | // |
11 | 13 | // Run with: go test -v -tags e2e -count=1 -timeout 10m ./test/e2e/... |
12 | 14 | package e2e |
@@ -42,15 +44,20 @@ var ( |
42 | 44 | ) |
43 | 45 |
|
44 | 46 | func TestMain(m *testing.M) { |
45 | | - adminURL = envOrDefault("A7_ADMIN_URL", "https://127.0.0.1:7443") |
46 | | - gatewayURL = envOrDefault("A7_GATEWAY_URL", "http://127.0.0.1:9080") |
47 | | - httpbinURL = envOrDefault("HTTPBIN_URL", "http://127.0.0.1:8080") |
| 47 | + adminURL = envOrDefault("A7_ADMIN_URL", "") |
| 48 | + gatewayURL = envOrDefault("A7_GATEWAY_URL", "") |
| 49 | + httpbinURL = envOrDefault("HTTPBIN_URL", "") |
48 | 50 | adminToken = envOrDefault("A7_TOKEN", "") |
49 | 51 |
|
50 | 52 | if g := os.Getenv("A7_GATEWAY_GROUP"); g != "" { |
51 | 53 | gatewayGroup = g |
52 | 54 | } |
53 | 55 |
|
| 56 | + if adminURL == "" { |
| 57 | + fmt.Fprintln(os.Stderr, "A7_ADMIN_URL environment variable is required for E2E tests") |
| 58 | + os.Exit(1) |
| 59 | + } |
| 60 | + |
54 | 61 | if adminToken == "" { |
55 | 62 | fmt.Fprintln(os.Stderr, "A7_TOKEN environment variable is required for E2E tests") |
56 | 63 | os.Exit(1) |
@@ -230,3 +237,17 @@ func resolveModuleRoot() (string, error) { |
230 | 237 | } |
231 | 238 | return filepath.Dir(gomod), nil |
232 | 239 | } |
| 240 | + |
| 241 | +func requireGatewayURL(t *testing.T) { |
| 242 | + t.Helper() |
| 243 | + if gatewayURL == "" { |
| 244 | + t.Skip("A7_GATEWAY_URL not set — skipping gateway traffic test") |
| 245 | + } |
| 246 | +} |
| 247 | + |
| 248 | +func requireHTTPBin(t *testing.T) { |
| 249 | + t.Helper() |
| 250 | + if httpbinURL == "" { |
| 251 | + t.Skip("HTTPBIN_URL not set — skipping httpbin-dependent test") |
| 252 | + } |
| 253 | +} |
0 commit comments