(t *testing.T)
| 944 | } |
| 945 | |
| 946 | func TestGenericsWithTransaction(t *testing.T) { |
| 947 | ctx := context.Background() |
| 948 | tx := DB.Begin() |
| 949 | if tx.Error != nil { |
| 950 | t.Fatalf("failed to begin transaction: %v", tx.Error) |
| 951 | } |
| 952 | |
| 953 | users := []User{{Name: "TestGenericsTransaction", Age: 18}, {Name: "TestGenericsTransaction2", Age: 18}} |
| 954 | err := gorm.G[User](tx).CreateInBatches(ctx, &users, 2) |
| 955 | |
| 956 | count, err := gorm.G[User](tx).Where("name like ?", "TestGenericsTransaction%").Count(ctx, "*") |
| 957 | if err != nil { |
| 958 | t.Fatalf("Count failed: %v", err) |
| 959 | } |
| 960 | if count != 2 { |
| 961 | t.Errorf("expected 2 records, got %d", count) |
| 962 | } |
| 963 | |
| 964 | if err := tx.Rollback().Error; err != nil { |
| 965 | t.Fatalf("failed to rollback transaction: %v", err) |
| 966 | } |
| 967 | |
| 968 | count2, err := gorm.G[User](DB).Where("name like ?", "TestGenericsTransaction%").Count(ctx, "*") |
| 969 | if err != nil { |
| 970 | t.Fatalf("Count failed: %v", err) |
| 971 | } |
| 972 | if count2 != 0 { |
| 973 | t.Errorf("expected 0 records after rollback, got %d", count2) |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | func TestGenericsToSQL(t *testing.T) { |
| 978 | ctx := context.Background() |
nothing calls this directly
no test coverage detected