lolly/internal/http3/mock_test.go
xfy 322573b9aa test(http2,http3,proxy): 改进测试覆盖边界情况
- http2/adapter_test.go: 替换 pool reuse 测试,新增 header 转换边界测试
  - 空头测试、特殊字符、多值头、长头名称
- http3/server_test.go: 替换 stats struct 测试,新增 Alt-Svc 头边界测试
  - 端口边界值、禁用服务器、nil 配置
- http3/mock_test.go: 添加 QUIC listener mock 用于测试
- proxy/proxy_test.go: 添加 UpstreamTiming 边界测试
  - 零值测试、部分标记测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:38:59 +08:00

41 lines
816 B
Go

// Package http3 提供测试用的 Mock 实现
package http3
import (
"context"
"net"
"github.com/quic-go/quic-go"
)
// MockQUICListener 是 QUIC 监听器的 Mock 实现
type MockQUICListener struct {
AcceptFunc func(ctx context.Context) (*quic.Conn, error)
CloseFunc func() error
AddrFunc func() net.Addr
}
// Accept 接受连接
func (m *MockQUICListener) Accept(ctx context.Context) (*quic.Conn, error) {
if m.AcceptFunc != nil {
return m.AcceptFunc(ctx)
}
return nil, nil
}
// Close 关闭监听器
func (m *MockQUICListener) Close() error {
if m.CloseFunc != nil {
return m.CloseFunc()
}
return nil
}
// Addr 返回监听地址
func (m *MockQUICListener) Addr() net.Addr {
if m.AddrFunc != nil {
return m.AddrFunc()
}
return &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 443}
}