From 6cc0fb6f03555fce12a79bcb756382736616b593 Mon Sep 17 00:00:00 2001 From: black Date: Mon, 20 Feb 2023 16:47:59 +0800 Subject: [PATCH] add test --- schema/schema_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/schema/schema_test.go b/schema/schema_test.go index 8a752fb7..14f02348 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -4,12 +4,38 @@ import ( "strings" "sync" "testing" + "time" "gorm.io/gorm" "gorm.io/gorm/schema" "gorm.io/gorm/utils/tests" ) +func TestParseCustomTypeSchema(t *testing.T) { + type Product struct { + Date time.Time `gorm:"type:date"` + Time time.Time `gorm:"type:time"` + DateTime time.Time + } + product, err := schema.Parse(&Product{}, &sync.Map{}, schema.NamingStrategy{}) + if err != nil { + t.Fatalf("failed to parse product, got err %v", err) + } + + fields := []schema.Field{ + {Name: "Date", DBName: "date", BindNames: []string{"Date"}, DataType: "date", CustomDataType: "date", Tag: `gorm:"type:date"`, TagSettings: map[string]string{"TYPE": "date"}}, + {Name: "Time", DBName: "time", BindNames: []string{"Time"}, DataType: schema.Time, CustomDataType: "time", Tag: `gorm:"type:time"`, TagSettings: map[string]string{"TYPE": "time"}}, + {Name: "DateTime", DBName: "date_time", BindNames: []string{"DateTime"}, DataType: schema.Time}, + } + for _, f := range fields { + checkSchemaField(t, product, &f, func(field *schema.Field) { + f.Creatable = true + f.Updatable = true + f.Readable = true + }) + } +} + func TestParseSchema(t *testing.T) { user, err := schema.Parse(&tests.User{}, &sync.Map{}, schema.NamingStrategy{}) if err != nil {