@@ -689,77 +689,3 @@ func TestTransactionWithRawSQL(t *testing.T) {
689
689
t .Errorf ("Expected age %d, got %d" , user .Age + 1 , result .Age )
690
690
}
691
691
}
692
-
693
- func TestTransactionCommit (t * testing.T ) {
694
- // Create test table
695
- type TestTxTable struct {
696
- ID uint `gorm:"primaryKey"`
697
- Name string `gorm:"size:100;column:name"`
698
- }
699
-
700
- err := DB .AutoMigrate (& TestTxTable {})
701
- if err != nil {
702
- t .Fatalf ("Failed to migrate test table: %v" , err )
703
- }
704
- defer DB .Migrator ().DropTable (& TestTxTable {})
705
-
706
- tx := DB .Begin ()
707
- if tx .Error != nil {
708
- t .Fatalf ("Failed to begin transaction: %v" , tx .Error )
709
- }
710
-
711
- record := TestTxTable {Name : "test_commit" }
712
- if err := tx .Create (& record ).Error ; err != nil {
713
- t .Errorf ("Failed to create record in transaction: %v" , err )
714
- }
715
-
716
- if err := tx .Commit ().Error ; err != nil {
717
- t .Errorf ("Failed to commit transaction: %v" , err )
718
- }
719
-
720
- // Verify record exists using quoted column name
721
- var count int64
722
- if err := DB .Model (& TestTxTable {}).Where ("\" name\" = ?" , "test_commit" ).Count (& count ).Error ; err != nil {
723
- t .Errorf ("Failed to count records: %v" , err )
724
- }
725
- if count != 1 {
726
- t .Errorf ("Expected 1 record after commit, got %d" , count )
727
- }
728
- }
729
-
730
- func TestTransactionRollback (t * testing.T ) {
731
- // Create test table
732
- type TestTxTable struct {
733
- ID uint `gorm:"primaryKey"`
734
- Name string `gorm:"size:100;column:name"`
735
- }
736
-
737
- err := DB .AutoMigrate (& TestTxTable {})
738
- if err != nil {
739
- t .Fatalf ("Failed to migrate test table: %v" , err )
740
- }
741
- defer DB .Migrator ().DropTable (& TestTxTable {})
742
-
743
- tx := DB .Begin ()
744
- if tx .Error != nil {
745
- t .Fatalf ("Failed to begin transaction: %v" , tx .Error )
746
- }
747
-
748
- record := TestTxTable {Name : "test_rollback" }
749
- if err := tx .Create (& record ).Error ; err != nil {
750
- t .Errorf ("Failed to create record in transaction: %v" , err )
751
- }
752
-
753
- if err := tx .Rollback ().Error ; err != nil {
754
- t .Errorf ("Failed to rollback transaction: %v" , err )
755
- }
756
-
757
- // Verify record doesn't exist using quoted column name
758
- var count int64
759
- if err := DB .Model (& TestTxTable {}).Where ("\" name\" = ?" , "test_rollback" ).Count (& count ).Error ; err != nil {
760
- t .Errorf ("Failed to count records: %v" , err )
761
- }
762
- if count != 0 {
763
- t .Errorf ("Expected 0 records after rollback, got %d" , count )
764
- }
765
- }
0 commit comments