Skip to content

Commit

Permalink
Fix tests and logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Jan 10, 2021
1 parent 7ebb320 commit 7302c8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion tests/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7302c8a

Please sign in to comment.