MCPcopy
hub / github.com/go-gorm/gorm / TestTransactionWithHooks

Function TestTransactionWithHooks

tests/transaction_test.go:453–479  ·  tests/transaction_test.go::TestTransactionWithHooks
(t *testing.T)

Source from the content-addressed store, hash-verified

451}
452
453func TestTransactionWithHooks(t *testing.T) {
454 user := GetUser("tTestTransactionWithHooks", Config{Account: true})
455 DB.Create(&user)
456
457 var err error
458 err = DB.Transaction(func(tx *gorm.DB) error {
459 return tx.Model(&User{}).Limit(1).Transaction(func(tx2 *gorm.DB) error {
460 return tx2.Scan(&User{}).Error
461 })
462 })
463 if err != nil {
464 t.Error(err)
465 }
466
467 // method with hooks
468 err = DB.Transaction(func(tx1 *gorm.DB) error {
469 // callMethod do
470 tx2 := tx1.Find(&User{}).Session(&gorm.Session{NewDB: true})
471 // trx in hooks
472 return tx2.Transaction(func(tx3 *gorm.DB) error {
473 return tx3.Where("user_id", user.ID).Delete(&Account{}).Error
474 })
475 })
476 if err != nil {
477 t.Error(err)
478 }
479}
480
481func TestTransactionWithDefaultTimeout(t *testing.T) {
482 db, err := OpenTestConnection(&gorm.Config{DefaultTransactionTimeout: 2 * time.Second})

Callers

nothing calls this directly

Calls 11

GetUserFunction · 0.85
TransactionMethod · 0.80
ModelMethod · 0.80
SessionMethod · 0.80
CreateMethod · 0.65
LimitMethod · 0.65
ScanMethod · 0.65
ErrorMethod · 0.65
FindMethod · 0.65
DeleteMethod · 0.65
WhereMethod · 0.65

Tested by

no test coverage detected