From 7302c8a136ea18ea184bc966329f26cdcaec0dc9 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 10 Jan 2021 15:27:53 +0800 Subject: [PATCH] Fix tests and logger --- logger/logger.go | 2 +- tests/update_test.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index 1206cf90..cd6bf57f 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -153,7 +153,7 @@ func (l logger) Trace(ctx context.Context, begin time.Time, fc func() (string, i } else { l.Printf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql) } - default: + case l.LogLevel == Info: sql, rows := fc() if rows == -1 { l.Printf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql) diff --git a/tests/update_test.go b/tests/update_test.go index be3e6fc9..c6764207 100644 --- a/tests/update_test.go +++ b/tests/update_test.go @@ -148,13 +148,17 @@ func TestUpdates(t *testing.T) { CheckUser(t, user2, *users[1]) // update with struct + time.Sleep(1 * time.Second) DB.Table("users").Where("name in ?", []string{users[1].Name}).Updates(User{Name: "updates_02_newname"}) var user3 User if err := DB.First(&user3, "name = ?", "updates_02_newname").Error; err != nil { t.Errorf("User2's name should be updated") } - AssertEqual(t, user2.UpdatedAt, user3.UpdatedAt) + + if user2.UpdatedAt.Format(time.RFC1123) == user3.UpdatedAt.Format(time.RFC1123) { + t.Errorf("User's updated at should be changed, old %v, new %v", user2.UpdatedAt.Format(time.RFC1123), user3.UpdatedAt.Format(time.RFC1123)) + } // update with gorm exprs if err := DB.Model(&user3).Updates(map[string]interface{}{"age": gorm.Expr("age + ?", 100)}).Error; err != nil {