lolly/internal/e2e/testutil/container_test.go
xfy 5d38d9ab44 test(e2e): 添加 E2E 测试工具包和配置
- 添加 testutil 容器管理工具(lolly/nginx)
- 添加测试配置文件(basic/proxy/ssl)
- 添加测试用 SSL 证书

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 09:35:19 +08:00

61 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//go:build e2e
// Package testutil 提供 E2E 测试的工具函数。
//
// 包含容器管理、测试配置、等待工具等。
//
// 作者xfy
package testutil
import (
"context"
"testing"
"time"
)
// TestContainerSetup 测试容器基础设施。
func TestContainerSetup(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
// 检查 Docker 是否可用
if !DockerAvailable(ctx) {
t.Skip("Docker not available, skipping E2E tests")
}
t.Log("Docker is available for E2E tests")
}
// TestDockerAvailable 测试 Docker 可用性检查。
func TestDockerAvailable(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
available := DockerAvailable(ctx)
t.Logf("Docker available: %v", available)
// 不强制要求 Docker 可用,只是报告状态
}
// TestMockBackendContainer 测试模拟后端容器启动。
func TestMockBackendContainer(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
if !DockerAvailable(ctx) {
t.Skip("Docker not available")
}
container, addr, err := MockBackendContainer(ctx, 80)
if err != nil {
t.Fatalf("Failed to start mock backend: %v", err)
}
defer container.Terminate(ctx)
t.Logf("Mock backend started at: %s", addr)
if addr == "" {
t.Error("Expected non-empty address")
}
}