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

Function TestMultipleStatements

testing/go/multi_statement_test.go:30–148  ·  view source on GitHub ↗

TestMultipleStatements is a test for: https://github.com/dolthub/doltgresql/issues/2175

(t *testing.T)

Source from the content-addressed store, hash-verified

28
29// TestMultipleStatements is a test for: https://github.com/dolthub/doltgresql/issues/2175
30func TestMultipleStatements(t *testing.T) {
31 ctx := context.Background()
32 var conn *Connection
33 if runOnPostgres {
34 pgxConn, err := pgx.Connect(ctx, "postgres://postgres:password@127.0.0.1:5432/postgres?sslmode=disable")
35 require.NoError(t, err)
36 conn = &Connection{
37 Default: pgxConn,
38 Current: pgxConn,
39 }
40 require.NoError(t, pgxConn.Ping(ctx))
41 defer func() {
42 conn.Close(ctx)
43 }()
44 } else {
45 var controller *svcs.Controller
46 ctx, conn, controller = CreateServer(t, "postgres")
47 defer func() {
48 conn.Close(ctx)
49 controller.Stop()
50 err := controller.WaitForStop()
51 require.NoError(t, err)
52 }()
53 }
54 queries := []string{
55 `BEGIN;`,
56 `DROP TABLE IF EXISTS migrations;`,
57 `DROP TABLE IF EXISTS animals;`,
58 `CREATE TABLE IF NOT EXISTS migrations (file_name TEXT NOT NULL, file_hash TEXT NOT NULL);`,
59 `CREATE TABLE IF NOT EXISTS animals (id SERIAL PRIMARY KEY NOT NULL, name TEXT NOT NULL);`,
60 `;`, // This should be ignored in the output
61 `INSERT INTO migrations (file_name, file_hash) VALUES ('2021-09-07T154500-create-animals-table.sql', '42331f4277227d09e9bb32eeaf7e04d9c7fe320160e05372ed0ef010cfbf666b');`,
62 `INSERT INTO animals(name) VALUES('Alpaca');`,
63 `INSERT INTO animals(name) VALUES('Highland cow');`,
64 `INSERT INTO animals(name) VALUES('Aardvark');`,
65 `INSERT INTO migrations (file_name, file_hash) VALUES ('2021-09-07T154700-insert-animals.sql', '3223d0deb6fb7fb2accf6abffc0667ebe4503379987c472d10a585a553f9b3b6');`,
66 `SELECT * FROM migrations ORDER BY file_name;`,
67 `SELECT * FROM animals ORDER BY id;`,
68 `COMMIT;`,
69 }
70 combinedQueries := ""
71 for _, query := range queries {
72 // We do this just to homogenize the queries, even though we're adding the delimiter right back
73 query = sql.RemoveSpaceAndDelimiter(query, ';')
74 combinedQueries += query + ";"
75 }
76 // First we'll check all invalid modes that fail immediately
77 invalidModes := []pgx.QueryExecMode{
78 pgx.QueryExecModeCacheStatement,
79 pgx.QueryExecModeCacheDescribe,
80 pgx.QueryExecModeDescribeExec,
81 pgx.QueryExecModeExec,
82 }
83 for _, mode := range invalidModes {
84 rows, err := conn.Current.Query(ctx, combinedQueries, mode)
85 if mode == pgx.QueryExecModeExec {
86 // This mode requires reading from the returned rows to find the error, rather than erroring immediately
87 require.NoError(t, err)

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
ConnectMethod · 0.80
ExecMethod · 0.80
CreateServerFunction · 0.70
CloseMethod · 0.65
LenMethod · 0.65
StopMethod · 0.45
QueryMethod · 0.45
NextMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected