(t *testing.T)
| 442 | } |
| 443 | |
| 444 | func TestReadOnlyTransaction(t *testing.T) { |
| 445 | if skipIntegrateTest { |
| 446 | t.Skip("Integration tests skipped") |
| 447 | } |
| 448 | |
| 449 | t.Run("begin ro, query, and close", func(t *testing.T) { |
| 450 | ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second) |
| 451 | defer cancel() |
| 452 | |
| 453 | session, tableId, tearDown := setup(t, ctx, []string{ |
| 454 | "INSERT INTO [[TABLE]] (id, active) VALUES (1, true), (2, false)", |
| 455 | }) |
| 456 | defer tearDown() |
| 457 | |
| 458 | // begin |
| 459 | stmt, err := BuildStatement("BEGIN RO") |
| 460 | if err != nil { |
| 461 | t.Fatalf("invalid statement: error=%s", err) |
| 462 | } |
| 463 | |
| 464 | result, err := stmt.Execute(ctx, session) |
| 465 | if err != nil { |
| 466 | t.Fatalf("unexpected error happened: %s", err) |
| 467 | } |
| 468 | |
| 469 | compareResult(t, result, &Result{ |
| 470 | AffectedRows: 0, |
| 471 | IsMutation: true, |
| 472 | }) |
| 473 | |
| 474 | // query |
| 475 | stmt, err = BuildStatement(fmt.Sprintf("SELECT id, active FROM %s ORDER BY id ASC", tableId)) |
| 476 | if err != nil { |
| 477 | t.Fatalf("invalid statement: error=%s", err) |
| 478 | } |
| 479 | |
| 480 | result, err = stmt.Execute(ctx, session) |
| 481 | if err != nil { |
| 482 | t.Fatalf("unexpected error happened: %s", err) |
| 483 | } |
| 484 | |
| 485 | compareResult(t, result, &Result{ |
| 486 | ColumnNames: []string{"id", "active"}, |
| 487 | Rows: []Row{ |
| 488 | Row{[]string{"1", "true"}}, |
| 489 | Row{[]string{"2", "false"}}, |
| 490 | }, |
| 491 | |
| 492 | ColumnTypes: []*pb.StructType_Field{ |
| 493 | {Name: "id", Type: &pb.Type{Code: pb.TypeCode_INT64}}, |
| 494 | {Name: "active", Type: &pb.Type{Code: pb.TypeCode_BOOL}}, |
| 495 | }, |
| 496 | AffectedRows: 2, |
| 497 | IsMutation: false, |
| 498 | }) |
| 499 | |
| 500 | // close |
| 501 | stmt, err = BuildStatement("CLOSE") |
nothing calls this directly
no test coverage detected