Skip to content
Open
Show file tree
Hide file tree
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
30 changes: 14 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,35 @@ go 1.24.0
toolchain go1.24.3

require (
github.com/stretchr/testify v1.11.1
gorm.io/driver/mysql v1.6.0
gorm.io/driver/postgres v1.6.0
gorm.io/driver/sqlite v1.6.0
gorm.io/driver/sqlserver v1.6.1
gorm.io/gorm v1.30.1
gorm.io/driver/sqlserver v1.6.3
gorm.io/gorm v1.31.1
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
filippo.io/edwards25519 v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-sql-driver/mysql v1.9.3 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.5 // indirect
github.com/jackc/pgx/v5 v5.8.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.32 // indirect
github.com/microsoft/go-mssqldb v1.9.2 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/tools v0.36.0 // indirect
gorm.io/cmd/gorm v0.1.1-0.20250825094947-30e7d4fa1f1f // indirect
gorm.io/datatypes v1.2.5 // indirect
gorm.io/hints v1.1.2 // indirect
gorm.io/plugin/dbresolver v1.6.0 // indirect
github.com/mattn/go-sqlite3 v1.14.34 // indirect
github.com/microsoft/go-mssqldb v1.9.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/text v0.34.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace gorm.io/gorm => ./gorm
49 changes: 30 additions & 19 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
package main

import (
"bytes"
"context"
"fmt"
"log/slog"
"path/filepath"
"runtime"
"testing"
"time"

"gorm.io/playground/models"
"github.com/stretchr/testify/require"
"gorm.io/gorm/logger"
"gorm.io/gorm/utils"
)

// GORM_REPO: https://github.com/go-gorm/gorm.git
// GORM_BRANCH: master
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver

func TestGORM(t *testing.T) {
user := models.User{Name: "jinzhu"}

DB.Create(&user)
func where() string {
return utils.FileWithLineNum()
}

var result models.User
if err := DB.First(&result, user.ID).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}
func TestFileWithLineNumExternal(t *testing.T) {
_, file, line, _ := runtime.Caller(0)
expectedLine := line + 2
got := where()
expectedSuffix := fmt.Sprintf("%s:%d", filepath.ToSlash(file), expectedLine)
require.Equal(t, expectedSuffix, got)
Comment on lines +30 to +31
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is named 'expectedSuffix' but is used in an exact equality check on line 31. If the intent is to check for an exact match, consider renaming to 'expected' or 'expectedPath' for clarity. If the intent is to verify a suffix match, the assertion should use a suffix check instead of exact equality.

Suggested change
expectedSuffix := fmt.Sprintf("%s:%d", filepath.ToSlash(file), expectedLine)
require.Equal(t, expectedSuffix, got)
expectedPath := fmt.Sprintf("%s:%d", filepath.ToSlash(file), expectedLine)
require.Equal(t, expectedPath, got)

Copilot uses AI. Check for mistakes.
}

// func TestGORMGen(t *testing.T) {
// user := models.User{Name: "jinzhu2"}
// ctx := context.Background()
func TestSlogCallerSource(t *testing.T) {
buf := &bytes.Buffer{}
handler := slog.NewTextHandler(buf, &slog.HandlerOptions{AddSource: true})
l := logger.NewSlogLogger(slog.New(handler), logger.Config{LogLevel: logger.Info})

// gorm.G[models.User](DB).Create(ctx, &user)
l.Trace(context.Background(), time.Now(), func() (string, int64) {
return "select 1", 0
}, nil)

// if u, err := gorm.G[models.User](DB).Where(g.User.ID.Eq(user.ID)).First(ctx); err != nil {
// t.Errorf("Failed, got error: %v", err)
// } else if u.Name != user.Name {
// t.Errorf("Failed, got user name: %v", u.Name)
// }
// }
out := buf.String()
require.NotContains(t, out, "gorm/logger/slog.go")
require.Contains(t, out, "playground/main_test.go")
}
Loading