RunScript runs the given script.
(t *testing.T, script ScriptTest, normalizeRows bool)
| 151 | |
| 152 | // RunScript runs the given script. |
| 153 | func RunScript(t *testing.T, script ScriptTest, normalizeRows bool) { |
| 154 | scriptDatabase := script.Database |
| 155 | if len(scriptDatabase) == 0 { |
| 156 | scriptDatabase = "postgres" |
| 157 | } |
| 158 | |
| 159 | var ctx context.Context |
| 160 | var conn *Connection |
| 161 | |
| 162 | if runOnPostgres { |
| 163 | ctx = context.Background() |
| 164 | pgxConn, err := pgx.Connect(ctx, fmt.Sprintf("postgres://postgres:password@127.0.0.1:%d/%s?sslmode=disable", 5432, scriptDatabase)) |
| 165 | require.NoError(t, err) |
| 166 | conn = &Connection{ |
| 167 | Default: pgxConn, |
| 168 | Current: pgxConn, |
| 169 | } |
| 170 | require.NoError(t, pgxConn.Ping(ctx)) |
| 171 | defer func() { |
| 172 | conn.Close(ctx) |
| 173 | }() |
| 174 | } else { |
| 175 | var controller *svcs.Controller |
| 176 | if script.UseLocalFileSystem { |
| 177 | port, err := sql.GetEmptyPort() |
| 178 | require.NoError(t, err) |
| 179 | ctx, conn, controller = CreateServerLocalWithPort(t, scriptDatabase, port) |
| 180 | } else { |
| 181 | ctx, conn, controller = CreateServer(t, scriptDatabase) |
| 182 | } |
| 183 | defer func() { |
| 184 | conn.Close(ctx) |
| 185 | controller.Stop() |
| 186 | err := controller.WaitForStop() |
| 187 | require.NoError(t, err) |
| 188 | }() |
| 189 | } |
| 190 | |
| 191 | t.Run(script.Name, func(t *testing.T) { |
| 192 | runScript(t, ctx, script, conn, normalizeRows) |
| 193 | }) |
| 194 | } |
| 195 | |
| 196 | // runScript runs the script given on the postgres connection provided |
| 197 | func runScript(t *testing.T, ctx context.Context, script ScriptTest, conn *Connection, normalizeRows bool) { |
no test coverage detected