Fix tests

This commit is contained in:
s-takehana 2021-07-14 04:25:42 +09:00 committed by GitHub
parent ba7731967a
commit 73bdeb7428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,17 +142,36 @@ func TestSmartMigrateColumn(t *testing.T) {
} }
func TestMigrateWithComment(t *testing.T) { func TestMigrateWithColumnComment(t *testing.T) {
type UserWithComment struct { type UserWithColumnComment struct {
gorm.Model gorm.Model
Name string `gorm:"size:111;index:,comment:这是一个index;comment:this is a 字段"` Name string `gorm:"size:111;comment:this is a 字段"`
} }
if err := DB.Migrator().DropTable(&UserWithComment{}); err != nil { if err := DB.Migrator().DropTable(&UserWithColumnComment{}); err != nil {
t.Fatalf("Failed to drop table, got error %v", err) t.Fatalf("Failed to drop table, got error %v", err)
} }
if err := DB.AutoMigrate(&UserWithComment{}); err != nil { if err := DB.AutoMigrate(&UserWithColumnComment{}); err != nil {
t.Fatalf("Failed to auto migrate, but got error %v", err)
}
}
func TestMigrateWithIndexComment(t *testing.T) {
if DB.Dialector.Name() != "mysql" {
t.Skip()
}
type UserWithIndexComment struct {
gorm.Model
Name string `gorm:"size:111;index:,comment:这是一个index"`
}
if err := DB.Migrator().DropTable(&UserWithIndexComment{}); err != nil {
t.Fatalf("Failed to drop table, got error %v", err)
}
if err := DB.AutoMigrate(&UserWithIndexComment{}); err != nil {
t.Fatalf("Failed to auto migrate, but got error %v", err) t.Fatalf("Failed to auto migrate, but got error %v", err)
} }
} }