lolly/internal/server/testutil.go
xfy 2734b04d8f refactor: remove 16.8k lines of dead code across all internal packages
- Delete unused files: tempfile subsystem, matcher variants, server/internal
- Remove 200+ unused functions across proxy, ssl, lua, http2/3, stream, variable
- Fix proxy test type errors (backgroundRefresh ctx→Request)
- Move bench/tools mock backend into internal/testutil
- Remove corresponding test functions for all deleted code
2026-06-03 16:15:43 +08:00

57 lines
1.3 KiB
Go

// Package server 提供测试工具函数和依赖注入支持
package server
import (
"crypto/tls"
"net"
"time"
"github.com/valyala/fasthttp"
"rua.plus/lolly/internal/lua"
"rua.plus/lolly/internal/ssl"
)
// testListenAddr 是测试用的随机端口监听地址
const testListenAddr = "127.0.0.1:0"
// MockFastServer 是 fasthttp.Server 的 Mock 包装
// 定义在此文件以便 TestServerOptions 可以引用
type MockFastServer struct {
Handler fasthttp.RequestHandler
TLSConfig *tls.Config
ServeFunc func(ln net.Listener) error
ServeTLSFunc func(ln net.Listener, certFile, keyFile string) error
ShutdownFunc func() error
Name string
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
MaxConnsPerIP int
MaxRequestsPerConn int
CloseOnShutdown bool
}
// TestDependencies 包含测试时可注入的依赖
// 使用具体指针类型,允许注入 Mock 实现
type TestDependencies struct {
LuaEngine *lua.LuaEngine
TLSManager *ssl.TLSManager
}
// TestServerOptions 测试服务器的可选配置
type TestServerOptions struct {
MockFastServer *MockFastServer
CustomHandler fasthttp.RequestHandler
SkipListener bool
DisableMiddleware bool
}