From 466dbbbc524de790c7333b0d3c89856f8e704351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=B9=96=E6=96=B0?= Date: Tue, 5 Dec 2023 20:47:11 +0900 Subject: [PATCH] dbresolver v1.5.0 regression example --- go.mod | 25 ++++++++++++++----------- main_test.go | 27 +++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 27e9ef2f..a62ae11d 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,12 @@ module gorm.io/playground go 1.20 require ( - gorm.io/driver/mysql v1.5.1 - gorm.io/driver/postgres v1.5.2 - gorm.io/driver/sqlite v1.5.3 - gorm.io/driver/sqlserver v1.5.1 - gorm.io/gorm v1.25.4 + gorm.io/driver/mysql v1.5.2 + gorm.io/driver/postgres v1.5.4 + gorm.io/driver/sqlite v1.5.4 + gorm.io/driver/sqlserver v1.5.2 + gorm.io/gorm v1.25.5 + gorm.io/plugin/dbresolver v1.5.0 ) require ( @@ -15,14 +16,16 @@ require ( github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.4.3 // indirect + github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect + github.com/jackc/pgx/v5 v5.5.0 // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/mattn/go-sqlite3 v1.14.17 // indirect - github.com/microsoft/go-mssqldb v1.5.0 // indirect - golang.org/x/crypto v0.12.0 // indirect - golang.org/x/text v0.12.0 // indirect + github.com/mattn/go-sqlite3 v1.14.18 // indirect + github.com/microsoft/go-mssqldb v1.6.0 // indirect + golang.org/x/crypto v0.16.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/text v0.14.0 // indirect ) replace gorm.io/gorm => ./gorm diff --git a/main_test.go b/main_test.go index 60a388f7..76d19bc8 100644 --- a/main_test.go +++ b/main_test.go @@ -1,7 +1,15 @@ package main import ( + "bytes" + "io" + "log" + "strings" "testing" + "time" + + "gorm.io/gorm/logger" + "gorm.io/plugin/dbresolver" ) // GORM_REPO: https://github.com/go-gorm/gorm.git @@ -9,12 +17,27 @@ import ( // TEST_DRIVERS: sqlite, mysql, postgres, sqlserver func TestGORM(t *testing.T) { - user := User{Name: "jinzhu"} + birthday := time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC) + user := User{Name: "jinzhu", Birthday: &birthday} DB.Create(&user) + var buf bytes.Buffer + DB.Logger = logger.New(log.New(io.Writer(&buf), "", 0), logger.Config{ + LogLevel: logger.Info, + }) + + DB.Use(dbresolver.Register(dbresolver.Config{ + TraceResolverMode: true, + })) + var result User - if err := DB.First(&result, user.ID).Error; err != nil { + if err := DB.Where("birthday = ?", birthday).First(&result, user.ID).Error; err != nil { t.Errorf("Failed, got error: %v", err) } + + substr := "[1990-01-01 00:00:00 +0000 UTC 1]" + if strings.Contains(buf.String(), substr) { + t.Errorf("Should not contain %v, but got %v", substr, buf.String()) + } }