add panic test

This commit is contained in:
leiyuqing 2022-04-03 12:04:01 +08:00
parent 46387c7b55
commit 201bf96f8e
3 changed files with 4 additions and 8 deletions

View File

@ -254,6 +254,10 @@ func TestUseDBInHooks(t *testing.T) {
t.Fatalf("Failed to create product, got error: %v", err)
}
testPanic := Product2{Name: "testPanic", Price: 100}
DB.Create(testPanic)
DB.Model(Product2{}).Where("name", "testPanic").Update("name", "testPanic1")
var result Product2
if err := DB.First(&result, "name = ?", "Nice").Error; err != nil {
t.Fatalf("Failed to query product, got error: %v", err)

View File

@ -763,7 +763,3 @@ func TestUpdateReturning(t *testing.T) {
t.Errorf("failed to return updated age column")
}
}
func TestAfterCreateWithPanic(t *testing.T) {
DB.Model(User{}).Where("name=?", "update-1").Update("name", "update-1-1")
}

View File

@ -31,10 +31,6 @@ type User struct {
Active bool
}
func (u *User) AfterCreate(tx *gorm.DB) error {
return nil
}
type Account struct {
gorm.Model
UserID sql.NullInt64