(t *testing.T)
| 292 | } |
| 293 | |
| 294 | func TestGenericsFindInBatches(t *testing.T) { |
| 295 | ctx := context.Background() |
| 296 | |
| 297 | users := []User{ |
| 298 | {Name: "GenericsFindBatchA"}, |
| 299 | {Name: "GenericsFindBatchB"}, |
| 300 | {Name: "GenericsFindBatchC"}, |
| 301 | {Name: "GenericsFindBatchD"}, |
| 302 | {Name: "GenericsFindBatchE"}, |
| 303 | } |
| 304 | if err := gorm.G[User](DB).CreateInBatches(ctx, &users, len(users)); err != nil { |
| 305 | t.Fatalf("CreateInBatches failed: %v", err) |
| 306 | } |
| 307 | |
| 308 | total := 0 |
| 309 | err := gorm.G[User](DB).Where("name like ?", "GenericsFindBatch%").FindInBatches(ctx, 2, func(chunk []User, batch int) error { |
| 310 | if len(chunk) > 2 { |
| 311 | t.Errorf("batch size exceed 2: got %d", len(chunk)) |
| 312 | } |
| 313 | |
| 314 | total += len(chunk) |
| 315 | return nil |
| 316 | }) |
| 317 | if err != nil { |
| 318 | t.Fatalf("FindInBatches failed: %v", err) |
| 319 | } |
| 320 | |
| 321 | if total != len(users) { |
| 322 | t.Errorf("expected total %d, got %d", len(users), total) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | func TestGenericsScopes(t *testing.T) { |
| 327 | ctx := context.Background() |
nothing calls this directly
no test coverage detected