From 2c10b8b58c54aab26a5dc81895b408a67a8e343b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=84=B1=EC=9A=B1?= Date: Thu, 7 Nov 2024 17:46:44 +0900 Subject: [PATCH] [#6372] Add test code --- tests/migrate_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/migrate_test.go b/tests/migrate_test.go index d955c8d7f2..850f63a86f 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -148,6 +148,8 @@ func TestSmartMigrateColumn(t *testing.T) { ID uint Name string Salary float64 + Bonus float64 `gorm:"not null"` + Stock float64 Birthday time.Time `gorm:"precision:4"` } @@ -157,8 +159,10 @@ func TestSmartMigrateColumn(t *testing.T) { type UserMigrateColumn2 struct { ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` + Bonus float64 + Stock float64 `gorm:"not null"` Birthday time.Time `gorm:"precision:2"` NameIgnoreMigration string `gorm:"size:100"` } @@ -182,6 +186,16 @@ func TestSmartMigrateColumn(t *testing.T) { if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) } + case "bonus": + // allow to change non-nullable to nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("bonus's nullable should be true, bug got %t", nullable) + } + case "stock": + // do not allow to change nullable to non-nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("stock's nullable should be true, bug got %t", nullable) + } case "birthday": if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("birthday's precision should be 2, but got %v", precision)