Fix tests and logger

This commit is contained in:
Jinzhu 2021-01-10 15:27:53 +08:00
parent 7ebb320f3e
commit 7302c8a136
2 changed files with 6 additions and 2 deletions

View File

@ -153,7 +153,7 @@ func (l logger) Trace(ctx context.Context, begin time.Time, fc func() (string, i
} else { } else {
l.Printf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql) l.Printf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql)
} }
default: case l.LogLevel == Info:
sql, rows := fc() sql, rows := fc()
if rows == -1 { if rows == -1 {
l.Printf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql) l.Printf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql)

View File

@ -148,13 +148,17 @@ func TestUpdates(t *testing.T) {
CheckUser(t, user2, *users[1]) CheckUser(t, user2, *users[1])
// update with struct // update with struct
time.Sleep(1 * time.Second)
DB.Table("users").Where("name in ?", []string{users[1].Name}).Updates(User{Name: "updates_02_newname"}) DB.Table("users").Where("name in ?", []string{users[1].Name}).Updates(User{Name: "updates_02_newname"})
var user3 User var user3 User
if err := DB.First(&user3, "name = ?", "updates_02_newname").Error; err != nil { if err := DB.First(&user3, "name = ?", "updates_02_newname").Error; err != nil {
t.Errorf("User2's name should be updated") 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 // update with gorm exprs
if err := DB.Model(&user3).Updates(map[string]interface{}{"age": gorm.Expr("age + ?", 100)}).Error; err != nil { if err := DB.Model(&user3).Updates(map[string]interface{}{"age": gorm.Expr("age + ?", 100)}).Error; err != nil {