This commit is contained in:
yun
2026-08-15 01:38:05 +08:00
parent 139330aee2
commit eb8f660ab5
57 changed files with 5401 additions and 1438 deletions
+44
View File
@@ -0,0 +1,44 @@
package mailx_test
import (
"context"
"testing"
mailx "code.yun.ink/pkg/mailx"
)
// recordingLogger 记录日志调用的最小实现
type recordingLogger struct{}
func (recordingLogger) Debugf(context.Context, string, ...any) {}
func (recordingLogger) Infof(context.Context, string, ...any) {}
func (recordingLogger) Warnf(context.Context, string, ...any) {}
func (recordingLogger) Errorf(context.Context, string, ...any) {}
var _ mailx.Logger = recordingLogger{}
func TestLoggerRoundTrip(t *testing.T) {
ctx := mailx.WithLogger(context.Background(), recordingLogger{})
l := mailx.LoggerFromContext(ctx)
if _, ok := l.(recordingLogger); !ok {
t.Fatalf("logger type = %T, want recordingLogger", l)
}
}
func TestLoggerDefaultNotNil(t *testing.T) {
l := mailx.LoggerFromContext(context.Background())
if l == nil {
t.Fatal("default logger should not be nil")
}
// 不应 panic
l.Debugf(context.Background(), "noop")
l.Infof(context.Background(), "noop")
l.Warnf(context.Background(), "noop")
l.Errorf(context.Background(), "noop")
}
func TestSetLoggerNilIgnored(t *testing.T) {
m := mailx.NewManager()
m.SetLogger(nil) // 不应 panic
m.SetLogger(recordingLogger{})
}