refactor: remove unused code identified by staticcheck

This commit is contained in:
xfy 2026-06-03 17:46:58 +08:00
parent 13547ec63e
commit 041bc97578
7 changed files with 2 additions and 76 deletions

View File

@ -444,11 +444,7 @@ func TestAppFields(t *testing.T) {
// customSig 实现自定义信号类型用于测试
type customSig struct{}
func (customSig) String() string { return "custom" }
func (customSig) Signal() {}

View File

@ -7,13 +7,5 @@
// 作者xfy
package app
import (
"rua.plus/lolly/internal/config"
"rua.plus/lolly/internal/logging"
)
// setupTestLogger 创建一个测试用的日志记录器。
// 返回一个使用默认配置的 AppLogger适用于测试场景。
func setupTestLogger() *logging.AppLogger {
return logging.NewAppLogger(&config.LoggingConfig{})
}

View File

@ -11,16 +11,8 @@
package http3
import (
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"math/big"
"net"
"testing"
"time"
"github.com/valyala/fasthttp"
"rua.plus/lolly/internal/config"
@ -134,40 +126,4 @@ func TestNewServer_Success(t *testing.T) {
// TestStart_InvalidListenAddress 测试无效监听地址
// generateTestCertificate 生成用于测试的自签名证书
func generateTestCertificate(t *testing.T) tls.Certificate {
t.Helper()
// 使用 RSA 密钥生成自签名证书
tmpl := &x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{CommonName: "localhost"},
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
DNSNames: []string{"localhost"},
IPAddresses: []net.IP{net.ParseIP("127.0.0.1")},
}
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
t.Fatalf("Failed to generate RSA key: %v", err)
}
certDER, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &priv.PublicKey, priv)
if err != nil {
t.Fatalf("Failed to create certificate: %v", err)
}
certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certDER})
keyPEM := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
cert, err := tls.X509KeyPair(certPEM, keyPEM)
if err != nil {
t.Fatalf("Failed to load certificate: %v", err)
}
return cert
}

View File

@ -88,12 +88,6 @@ func (m *mockResolver) Stats() resolver.Stats {
}
}
func (m *mockResolver) getLookupWithCacheCalls() int {
m.mu.RLock()
defer m.mu.RUnlock()
return m.lookupWithCacheCalls
}
// TestSetResolver 测试设置 DNS 解析器。
func TestSetResolver(t *testing.T) {
cfg := &config.ProxyConfig{

View File

@ -302,7 +302,6 @@ func BenchmarkPoolMemoryReuse(b *testing.B) {
// 模拟池化结构体
type pooledTask struct {
data []byte
id int
}
taskPool := &sync.Pool{

View File

@ -11,9 +11,6 @@ import (
"rua.plus/lolly/internal/ssl"
)
// testListenAddr 是测试用的随机端口监听地址
const testListenAddr = "127.0.0.1:0"
// MockFastServer 是 fasthttp.Server 的 Mock 包装
// 定义在此文件以便 TestServerOptions 可以引用
type MockFastServer struct {

View File

@ -287,12 +287,4 @@ func TestGetInheritedListeners_EnvPreserved(t *testing.T) {
}
}
// containsString 检查字符串是否包含子串
func containsString(s, substr string) bool {
for i := 0; i <= len(s)-len(substr); i++ {
if s[i:i+len(substr)] == substr {
return true
}
}
return false
}