fix: 完成商务迁移复核与接口优化并清理历史资料

This commit is contained in:
Yvan
2026-11-04 14:45:02 +08:00
parent 5a96be6a79
commit 297e80827d
176 changed files with 6803 additions and 6002 deletions
+45
View File
@@ -0,0 +1,45 @@
package gormkit
import (
"bytes"
"context"
"errors"
"log/slog"
"testing"
"time"
"gorm.io/gorm/logger"
)
func TestTraceOnlyFormatsQueriesThatWillBeLogged(t *testing.T) {
for _, tc := range []struct {
name string
gorm logger.LogLevel
app slog.Level
duration time.Duration
err error
want bool
}{
{"silent", logger.Silent, slog.LevelInfo, time.Second, errors.New("failure"), false},
{"successful error-only", logger.Error, slog.LevelInfo, time.Second, nil, false},
{"fast warning-only", logger.Warn, slog.LevelInfo, time.Millisecond, nil, false},
{"not-found warning-only", logger.Warn, slog.LevelInfo, time.Millisecond, logger.ErrRecordNotFound, false},
{"application filter", logger.Info, slog.LevelError, time.Millisecond, nil, false},
{"slow", logger.Warn, slog.LevelInfo, time.Second, nil, true},
{"error", logger.Error, slog.LevelInfo, time.Millisecond, errors.New("failure"), true},
{"info", logger.Info, slog.LevelInfo, time.Millisecond, nil, true},
} {
t.Run(tc.name, func(t *testing.T) {
var buffer bytes.Buffer
log := NewLogger(slog.New(slog.NewJSONHandler(&buffer, &slog.HandlerOptions{Level: tc.app})), tc.gorm)
calls := 0
log.Trace(context.Background(), time.Now().Add(-tc.duration), func() (string, int64) {
calls++
return "SELECT 1", 1
}, tc.err)
if (calls == 1) != tc.want || (buffer.Len() > 0) != tc.want {
t.Fatalf("format calls=%d, output=%q, want logging=%v", calls, buffer.String(), tc.want)
}
})
}
}