MCPcopy Create free account
hub / github.com/cloudspannerecosystem/spanner-cli / TestTruncateTable

Function TestTruncateTable

integration_test.go:682–716  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

680}
681
682func 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
718func TestPartitionedDML(t *testing.T) {
719 if skipIntegrateTest {

Callers

nothing calls this directly

Calls 3

setupFunction · 0.85
BuildStatementFunction · 0.85
ExecuteMethod · 0.65

Tested by

no test coverage detected