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

Function TestTransactionOnClosedConn

tests/transaction_test.go:432–451  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

430}
431
432func TestTransactionOnClosedConn(t *testing.T) {
433 DB, err := OpenTestConnection(&gorm.Config{})
434 if err != nil {
435 t.Fatalf("failed to connect database, got error %v", err)
436 }
437 rawDB, _ := DB.DB()
438 rawDB.Close()
439
440 if err := DB.Transaction(func(tx *gorm.DB) error {
441 return nil
442 }); err == nil {
443 t.Errorf("should returns error when commit with closed conn, got error %v", err)
444 }
445
446 if err := DB.Session(&gorm.Session{PrepareStmt: true}).Transaction(func(tx *gorm.DB) error {
447 return nil
448 }); err == nil {
449 t.Errorf("should returns error when commit with closed conn, got error %v", err)
450 }
451}
452
453func TestTransactionWithHooks(t *testing.T) {
454 user := GetUser("tTestTransactionWithHooks", Config{Account: true})

Callers

nothing calls this directly

Calls 5

OpenTestConnectionFunction · 0.85
DBMethod · 0.80
TransactionMethod · 0.80
SessionMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected