Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package main

import (
"bytes"
"context"
"log/slog"
"strings"
"testing"
"time"

"gorm.io/playground/models"
)
Expand All @@ -21,6 +26,24 @@ func TestGORM(t *testing.T) {
}
}

func TestSlogLogger(t *testing.T) {
buf := &bytes.Buffer{}
handler := slog.NewTextHandler(buf, &slog.HandlerOptions{AddSource: true})
logger := NewSlogLogger(slog.New(handler), Config{LogLevel: Info})

logger.Trace(context.Background(), time.Now(), func() (string, int64) {
return "select count(*) from users", 0
}, nil)

if strings.Contains(buf.String(), "gorm/logger/slog.go") {
t.Error("Found internal slog.go reference in caller frame. Expected only test file references.")
}

if !strings.Contains(buf.String(), "main_test.go") {
t.Error("Missing expected test file reference. 'main_test.go' should appear in caller frames.")
}
}

// func TestGORMGen(t *testing.T) {
// user := models.User{Name: "jinzhu2"}
// ctx := context.Background()
Expand Down
Loading