MCPcopy Create free account
hub / github.com/dolthub/doltgresql / RunScriptN

Function RunScriptN

testing/go/prepared_statement_test.go:1498–1562  ·  view source on GitHub ↗

RunScriptN runs the assertions of the given script n times using the same connection

(t *testing.T, script ScriptTest, n int)

Source from the content-addressed store, hash-verified

1496
1497// RunScriptN runs the assertions of the given script n times using the same connection
1498func RunScriptN(t *testing.T, script ScriptTest, n int) {
1499 scriptDatabase := script.Database
1500 if len(scriptDatabase) == 0 {
1501 scriptDatabase = "postgres"
1502 }
1503 ctx, conn, controller := CreateServer(t, scriptDatabase)
1504 defer func() {
1505 conn.Close(ctx)
1506 controller.Stop()
1507 err := controller.WaitForStop()
1508 require.NoError(t, err)
1509 }()
1510
1511 // Run the setup
1512 for _, query := range script.SetUpScript {
1513 rows, err := conn.Query(ctx, query)
1514 require.NoError(t, err)
1515 _, _, err = ReadRows(rows, true)
1516 assert.NoError(t, err)
1517 }
1518
1519 for i := 0; i < n; i++ {
1520 t.Run(script.Name, func(t *testing.T) {
1521 // Run the assertions
1522 for _, assertion := range script.Assertions {
1523 t.Run(assertion.Query, func(t *testing.T) {
1524 if assertion.Skip {
1525 t.Skip("Skip has been set in the assertion")
1526 }
1527 rows, err := conn.Query(ctx, assertion.Query)
1528 if err == nil {
1529 defer rows.Close()
1530 }
1531
1532 var errorSeen string
1533
1534 if assertion.ExpectedErr == "" {
1535 require.NoError(t, err)
1536 } else if err != nil {
1537 errorSeen = err.Error()
1538 }
1539
1540 if errorSeen == "" {
1541 foundRows, foundRawRows, err := ReadRows(rows, true)
1542 if assertion.ExpectedErr == "" {
1543 require.NoError(t, err)
1544 if assertion.ExpectedRaw != nil {
1545 assert.Equal(t, assertion.ExpectedRaw, foundRawRows)
1546 } else {
1547 assert.Equal(t, NormalizeExpectedRow(rows.FieldDescriptions(), assertion.Expected), foundRows)
1548 }
1549 } else if err != nil {
1550 errorSeen = err.Error()
1551 }
1552 }
1553
1554 if assertion.ExpectedErr != "" {
1555 require.False(t, errorSeen == "", "Expected error but got none")

Callers 1

Calls 10

NormalizeExpectedRowFunction · 0.85
RunMethod · 0.80
CreateServerFunction · 0.70
ReadRowsFunction · 0.70
CloseMethod · 0.65
StopMethod · 0.45
QueryMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected