Skip to content

Commit b091b56

Browse files
committed
[go-gorm#6372] Fix failed test case
1 parent 72695c5 commit b091b56

File tree

2 files changed

+16
-71
lines changed

2 files changed

+16
-71
lines changed

tests/automigration_test.go

-69
This file was deleted.

tests/migrate_test.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func TestSmartMigrateColumn(t *testing.T) {
148148
ID uint
149149
Name string
150150
Salary float64
151+
Bonus float64 `gorm:"not null"`
152+
Stock float64
151153
Birthday time.Time `gorm:"precision:4"`
152154
}
153155

@@ -157,8 +159,10 @@ func TestSmartMigrateColumn(t *testing.T) {
157159

158160
type UserMigrateColumn2 struct {
159161
ID uint
160-
Name string `gorm:"size:128"`
161-
Salary float64 `gorm:"precision:2"`
162+
Name string `gorm:"size:128"`
163+
Salary float64 `gorm:"precision:2"`
164+
Bonus float64
165+
Stock float64 `gorm:"not null"`
162166
Birthday time.Time `gorm:"precision:2"`
163167
NameIgnoreMigration string `gorm:"size:100"`
164168
}
@@ -182,6 +186,16 @@ func TestSmartMigrateColumn(t *testing.T) {
182186
if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 {
183187
t.Fatalf("salary's precision should be 2, but got %v %v", precision, o)
184188
}
189+
case "bonus":
190+
// allow to change non-nullable to nullable
191+
if nullable, _ := columnType.Nullable(); !nullable {
192+
t.Fatalf("bonus's nullable should be true, bug got %t", nullable)
193+
}
194+
case "stock":
195+
// do not allow to change nullable to non-nullable
196+
if nullable, _ := columnType.Nullable(); !nullable {
197+
t.Fatalf("stock's nullable should be true, bug got %t", nullable)
198+
}
185199
case "birthday":
186200
if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 {
187201
t.Fatalf("birthday's precision should be 2, but got %v", precision)

0 commit comments

Comments
 (0)