2026-05-02 23:39:10 +08:00
|
|
|
package log
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// MockRequestLog 用于测试池化逻辑
|
|
|
|
|
type MockRequestLog struct {
|
|
|
|
|
BaseLog
|
|
|
|
|
RequestId string
|
|
|
|
|
UsedTime float32
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-09 14:44:41 +08:00
|
|
|
func (l *MockRequestLog) Reset() {
|
|
|
|
|
l.BaseLog.Reset()
|
|
|
|
|
l.RequestId = ""
|
|
|
|
|
l.UsedTime = 0
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-02 23:39:10 +08:00
|
|
|
func TestWithEntry(t *testing.T) {
|
2026-05-05 13:23:25 +08:00
|
|
|
WithEntry(func(entry *MockRequestLog) {
|
2026-05-02 23:39:10 +08:00
|
|
|
entry.RequestId = "with-entry-id"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 验证 PutEntry 自动被调用
|
2026-05-05 13:23:25 +08:00
|
|
|
entry2 := GetEntry[MockRequestLog]()
|
2026-05-02 23:39:10 +08:00
|
|
|
if entry2.RequestId != "" {
|
|
|
|
|
t.Errorf("Expected reset, got %s", entry2.RequestId)
|
|
|
|
|
}
|
|
|
|
|
}
|