(t *testing.T)
| 680 | } |
| 681 | |
| 682 | func TestTruncateTable(t *testing.T) { |
| 683 | if skipIntegrateTest { |
| 684 | t.Skip("Integration tests skipped") |
| 685 | } |
| 686 | |
| 687 | ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second) |
| 688 | defer cancel() |
| 689 | |
| 690 | session, tableId, tearDown := setup(t, ctx, []string{ |
| 691 | "INSERT INTO [[TABLE]] (id, active) VALUES (1, true), (2, false)", |
| 692 | }) |
| 693 | defer tearDown() |
| 694 | |
| 695 | stmt, err := BuildStatement(fmt.Sprintf("TRUNCATE TABLE %s", tableId)) |
| 696 | if err != nil { |
| 697 | t.Fatalf("invalid statement: %v", err) |
| 698 | } |
| 699 | |
| 700 | if _, err := stmt.Execute(ctx, session); err != nil { |
| 701 | t.Fatalf("execution failed: %v", err) |
| 702 | } |
| 703 | |
| 704 | // We don't use the TRUNCATE TABLE's result since PartitionedUpdate may return estimated affected row counts. |
| 705 | // Instead, we check if rows are remained in the table. |
| 706 | var count int64 |
| 707 | countStmt := spanner.NewStatement(fmt.Sprintf("SELECT COUNT(*) FROM %s", tableId)) |
| 708 | if err := session.client.Single().Query(ctx, countStmt).Do(func(r *spanner.Row) error { |
| 709 | return r.Column(0, &count) |
| 710 | }); err != nil { |
| 711 | t.Fatalf("query failed: %v", err) |
| 712 | } |
| 713 | if count != 0 { |
| 714 | t.Errorf("TRUNCATE TABLE executed, but %d rows are remained", count) |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | func TestPartitionedDML(t *testing.T) { |
| 719 | if skipIntegrateTest { |
nothing calls this directly
no test coverage detected