From cd54dddd94a992edd446611aeccc939a64ad2658 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 27 Aug 2020 18:42:40 +0800 Subject: [PATCH] Test update with GormValuer --- tests/go.mod | 2 +- tests/scanner_valuer_test.go | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/go.mod b/tests/go.mod index 9d4e892d..b0ed4497 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -9,7 +9,7 @@ require ( gorm.io/driver/mysql v0.3.2 gorm.io/driver/postgres v0.2.9 gorm.io/driver/sqlite v1.0.9 - gorm.io/driver/sqlserver v0.2.7 + gorm.io/driver/sqlserver v0.2.8 gorm.io/gorm v0.2.36 ) diff --git a/tests/scanner_valuer_test.go b/tests/scanner_valuer_test.go index dbf5adac..f42daae7 100644 --- a/tests/scanner_valuer_test.go +++ b/tests/scanner_valuer_test.go @@ -314,10 +314,6 @@ type Point struct { X, Y int } -func (point *Point) Scan(v interface{}) error { - return nil -} - func (point Point) GormDataType() string { return "geo" } @@ -379,4 +375,19 @@ func TestGORMValuer(t *testing.T) { if !reflect.DeepEqual([]interface{}{"jinzhu", "POINT(100 100)"}, stmt.Vars) { t.Errorf("generated vars is not equal, got %v", stmt.Vars) } + + stmt = dryRunDB.Session(&gorm.Session{ + AllowGlobalUpdate: true, + }).Model(&UserWithPoint{}).Updates(UserWithPoint{ + Name: "jinzhu", + Point: Point{X: 100, Y: 100}, + }).Statement + + if !regexp.MustCompile(`UPDATE .user_with_points. SET .name.=.+,.point.=ST_PointFromText\(.+\)`).MatchString(stmt.SQL.String()) { + t.Errorf("insert with sql.Expr, but got %v", stmt.SQL.String()) + } + + if !reflect.DeepEqual([]interface{}{"jinzhu", "POINT(100 100)"}, stmt.Vars) { + t.Errorf("generated vars is not equal, got %v", stmt.Vars) + } }