|
153 | 153 | ) filteredSqlTests;
|
154 | 154 | sortedTestList = builtins.sort (a: b: a < b) testList;
|
155 | 155 | in
|
156 |
| - pkgs.runCommand "postgres-${pgpkg.version}-check-harness" |
157 |
| - { |
158 |
| - nativeBuildInputs = with pkgs; [ |
159 |
| - coreutils |
160 |
| - bash |
161 |
| - perl |
162 |
| - pgpkg |
163 |
| - pg_prove |
164 |
| - pg_regress |
165 |
| - procps |
166 |
| - start-postgres-server-bin |
167 |
| - which |
168 |
| - getkey-script |
169 |
| - supabase-groonga |
170 |
| - python3 |
171 |
| - netcat |
172 |
| - ]; |
173 |
| - } |
174 |
| - '' |
| 156 | + pkgs.writeShellApplication rec { |
| 157 | + name = "postgres-${pgpkg.version}-check-harness"; |
| 158 | + bashOptions = [ |
| 159 | + "nounset" |
| 160 | + "pipefail" |
| 161 | + ]; |
| 162 | + runtimeInputs = with pkgs; [ |
| 163 | + coreutils |
| 164 | + bash |
| 165 | + perl |
| 166 | + pgpkg |
| 167 | + pg_prove |
| 168 | + pg_regress |
| 169 | + procps |
| 170 | + start-postgres-server-bin |
| 171 | + which |
| 172 | + getkey-script |
| 173 | + supabase-groonga |
| 174 | + python3 |
| 175 | + netcat |
| 176 | + ]; |
| 177 | + |
| 178 | + text = '' |
| 179 | +
|
| 180 | + #shellcheck disable=SC1091 |
175 | 181 | source ${bashlog}
|
176 |
| - set -uo pipefail |
| 182 | + #shellcheck disable=SC1091 |
| 183 | + source ${pkgs.stdenv}/setup |
| 184 | + export PATH="${lib.makeBinPath runtimeInputs}:$PATH" |
177 | 185 |
|
178 | 186 | export BASHLOG_FILE=1
|
179 | 187 | export BASHLOG_FILE_PATH=debug.log
|
|
184 | 192 | function log_cmd {
|
185 | 193 | local cmd_name="$1"
|
186 | 194 | shift
|
187 |
| - log debug "Executing: $cmd_name $@" |
| 195 | + log debug "Executing: $cmd_name $*" |
188 | 196 | local exit_code=0
|
189 |
| - echo "\$ $cmd_name $@" >> debug.log |
190 |
| - "$cmd_name" "$@" 2>&1 >> debug.log || exit_code=$? |
| 197 | + echo "\$ $cmd_name $*" >> debug.log |
| 198 | +
|
| 199 | + "$cmd_name" "$@" >> debug.log 2>&1 || exit_code=$? |
191 | 200 | log debug "Exit code: $exit_code"
|
192 | 201 | return $exit_code
|
193 | 202 | }
|
|
207 | 216 |
|
208 | 217 | function check_postgres_ready {
|
209 | 218 | for i in {1..60}; do
|
210 |
| - if log_cmd pg_isready -h ${self.supabase.defaults.host} -p ${pgPort} -U supabase_admin -q; then |
| 219 | + if log_cmd pg_isready -h localhost -p ${pgPort} -U supabase_admin -q; then |
211 | 220 | log info "PostgreSQL is ready"
|
212 | 221 | break
|
213 | 222 | fi
|
214 | 223 | sleep 1
|
215 |
| - if [ $i -eq 60 ]; then |
| 224 | + if [ "$i" -eq 60 ]; then |
216 | 225 | log error "PostgreSQL failed to start"
|
217 | 226 | exit 1
|
218 | 227 | fi
|
|
253 | 262 | log_cmd initdb --locale=C --username=supabase_admin -D "$PGTAP_CLUSTER"
|
254 | 263 | substitute ${./tests/postgresql.conf.in} "$PGTAP_CLUSTER"/postgresql.conf \
|
255 | 264 | --subst-var-by PGSODIUM_GETKEY_SCRIPT "${getkey-script}/bin/pgsodium-getkey"
|
256 |
| - echo "listen_addresses = '*'" >> "$PGTAP_CLUSTER"/postgresql.conf |
| 265 | + echo "listen_addresses = '127.0.0.1'" >> "$PGTAP_CLUSTER"/postgresql.conf |
257 | 266 | echo "port = ${pgPort}" >> "$PGTAP_CLUSTER"/postgresql.conf
|
258 |
| - echo "host all all 127.0.0.1/32 trust" >> $PGTAP_CLUSTER/pg_hba.conf |
| 267 | + echo "host all all 127.0.0.1/32 trust" >> "$PGTAP_CLUSTER/pg_hba.conf" |
259 | 268 | log info "Checking shared_preload_libraries setting:"
|
260 |
| - log info $(grep -rn "shared_preload_libraries" "$PGTAP_CLUSTER"/postgresql.conf) |
| 269 | + log info "$(grep -rn "shared_preload_libraries" "$PGTAP_CLUSTER"/postgresql.conf)" |
261 | 270 | # Remove timescaledb if running orioledb-17 check
|
262 | 271 | log info "pgpkg.version is: ${pgpkg.version}"
|
| 272 | + #shellcheck disable=SC2193 |
263 | 273 | if [[ "${pgpkg.version}" == *"17"* ]]; then
|
264 | 274 | perl -pi -e 's/ timescaledb,//g' "$PGTAP_CLUSTER/postgresql.conf"
|
265 | 275 | fi
|
|
273 | 283 |
|
274 | 284 | # PostgreSQL startup
|
275 | 285 | if [[ "$(uname)" == "Darwin" ]]; then
|
276 |
| - log_cmd pg_ctl -D "$PGTAP_CLUSTER" -l "$PGTAP_CLUSTER"/postgresql.log -o "-k "$PGTAP_CLUSTER" -p ${pgPort} -d 5" start |
| 286 | + log_cmd pg_ctl -D "$PGTAP_CLUSTER" -l "$PGTAP_CLUSTER/postgresql.log" -o "-k $PGTAP_CLUSTER -p ${pgPort} -d 5" start |
277 | 287 | else
|
278 | 288 | mkdir -p "$PGTAP_CLUSTER/sockets"
|
279 |
| - log_cmd pg_ctl -D "$PGTAP_CLUSTER" -l "$PGTAP_CLUSTER"/postgresql.log -o "-k $PGTAP_CLUSTER/sockets -p ${pgPort} -d 5" start |
| 289 | + log_cmd pg_ctl -D "$PGTAP_CLUSTER" -l "$PGTAP_CLUSTER/postgresql.log" -o "-k $PGTAP_CLUSTER/sockets -p ${pgPort} -d 5" start |
280 | 290 | fi || {
|
281 | 291 | log error "pg_ctl failed to start PostgreSQL"
|
282 | 292 | log error "Contents of postgresql.log:"
|
|
288 | 298 | check_postgres_ready
|
289 | 299 |
|
290 | 300 | log info "Creating test database"
|
291 |
| - log_cmd createdb -p ${pgPort} -h ${self.supabase.defaults.host} --username=supabase_admin testing |
| 301 | + log_cmd createdb -p ${pgPort} -h localhost --username=supabase_admin testing |
292 | 302 |
|
293 | 303 | log info "Loading prime SQL file"
|
294 |
| - if ! log_cmd psql -p ${pgPort} -h ${self.supabase.defaults.host} --username=supabase_admin -d testing -v ON_ERROR_STOP=1 -Xf ${./tests/prime.sql}; then |
| 304 | + if ! log_cmd psql -p ${pgPort} -h localhost --username=supabase_admin -d testing -v ON_ERROR_STOP=1 -Xf ${./tests/prime.sql}; then |
295 | 305 | log error "Error executing SQL file. PostgreSQL log content:"
|
296 | 306 | cat "$PGTAP_CLUSTER"/postgresql.log
|
297 | 307 | pg_ctl -D "$PGTAP_CLUSTER" stop
|
|
300 | 310 |
|
301 | 311 | # Create a table to store test configuration
|
302 | 312 | log info "Creating test_config table"
|
303 |
| - log_cmd psql -p ${pgPort} -h ${self.supabase.defaults.host} --username=supabase_admin -d testing -c " |
| 313 | + log_cmd psql -p ${pgPort} -h localhost --username=supabase_admin -d testing -c " |
304 | 314 | CREATE TABLE IF NOT EXISTS test_config (key TEXT PRIMARY KEY, value TEXT);
|
305 | 315 | INSERT INTO test_config (key, value) VALUES ('http_mock_port', '$HTTP_MOCK_PORT')
|
306 | 316 | ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
|
|
309 | 319 | for t in $(printf "%s\n" ${builtins.concatStringsSep " " sortedTestList}); do
|
310 | 320 | log info "Running pgtap test: $t.sql"
|
311 | 321 | #XXX enable ON_ERROR_STOP ?
|
312 |
| - log_cmd psql -p ${pgPort} -h ${self.supabase.defaults.host} --username=supabase_admin -d testing -f "${./tests/sql}/$t.sql" |
| 322 | + log_cmd psql -p ${pgPort} -h localhost --username=supabase_admin -d testing -f "${./tests/sql}/$t.sql" |
313 | 323 | done
|
314 | 324 | rm -rf "$SORTED_DIR"
|
315 | 325 | log_cmd pg_ctl -D "$PGTAP_CLUSTER" stop
|
316 |
| - rm -rf $PGTAP_CLUSTER |
| 326 | + rm -rf "$PGTAP_CLUSTER" |
317 | 327 |
|
318 | 328 | # End of pgtap tests
|
319 | 329 | # from here on out we are running pg_regress tests, we use a different cluster for this
|
|
322 | 332 |
|
323 | 333 | log info "Starting PostgreSQL server for pg_regress tests"
|
324 | 334 | unset GRN_PLUGINS_DIR
|
325 |
| - log_cmd ${start-postgres-server-bin}/bin/start-postgres-server ${getVersionArg pgpkg} --daemonize |
| 335 | + if ! log_cmd ${start-postgres-server-bin}/bin/start-postgres-server ${getVersionArg pgpkg} --daemonize; then |
| 336 | + log error "Failed to start PostgreSQL server for pg_regress tests" |
| 337 | + exit 1 |
| 338 | + fi |
326 | 339 |
|
327 | 340 | check_postgres_ready
|
328 | 341 |
|
329 | 342 | log info "Loading prime SQL file"
|
330 |
| - if ! log_cmd psql -p ${pgPort} -h ${self.supabase.defaults.host} --no-password --username=supabase_admin -d postgres -v ON_ERROR_STOP=1 -Xf ${./tests/prime.sql} 2>&1; then |
| 343 | + if ! log_cmd psql -p ${pgPort} -h localhost --no-password --username=supabase_admin -d postgres -v ON_ERROR_STOP=1 -Xf ${./tests/prime.sql} 2>&1; then |
331 | 344 | log error "Error executing SQL file"
|
332 | 345 | exit 1
|
333 | 346 | fi
|
334 | 347 |
|
335 | 348 | # Create a table to store test configuration for pg_regress tests
|
336 | 349 | log info "Creating test_config table for pg_regress tests"
|
337 |
| - log_cmd psql -p ${pgPort} -h ${self.supabase.defaults.host} --no-password --username=supabase_admin -d postgres -c " |
| 350 | + log_cmd psql -p ${pgPort} -h localhost --no-password --username=supabase_admin -d postgres -c " |
338 | 351 | CREATE TABLE IF NOT EXISTS test_config (key TEXT PRIMARY KEY, value TEXT);
|
339 | 352 | INSERT INTO test_config (key, value) VALUES ('http_mock_port', '$HTTP_MOCK_PORT')
|
340 | 353 | ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
|
341 | 354 | "
|
342 | 355 |
|
343 |
| - mkdir -p $out/regression_output |
| 356 | + #shellcheck disable=SC2154 |
| 357 | + mkdir -p "$out/regression_output" |
344 | 358 | log info "Running pg_regress tests"
|
345 | 359 | if ! log_cmd pg_regress \
|
346 | 360 | --use-existing \
|
347 | 361 | --dbname=postgres \
|
348 | 362 | --inputdir=${./tests} \
|
349 |
| - --outputdir=$out/regression_output \ |
350 |
| - --host=${self.supabase.defaults.host} \ |
| 363 | + --outputdir="$out/regression_output" \ |
| 364 | + --host=localhost \ |
351 | 365 | --port=${pgPort} \
|
352 | 366 | --user=supabase_admin \
|
353 | 367 | ${builtins.concatStringsSep " " sortedTestList} 2>&1; then
|
354 | 368 | log error "pg_regress tests failed"
|
355 |
| - cat $out/regression_output/regression.diffs |
| 369 | + cat "$out/regression_output/regression.diffs" |
356 | 370 | exit 1
|
357 | 371 | fi
|
358 | 372 | log info "pg_regress tests completed successfully"
|
359 | 373 |
|
360 | 374 | log info "Running migrations tests"
|
361 |
| - log_cmd pg_prove -p ${pgPort} -U supabase_admin -h ${self.supabase.defaults.host} -d postgres -v ${../migrations/tests}/test.sql |
| 375 | + log_cmd pg_prove -p ${pgPort} -U supabase_admin -h localhost -d postgres -v ${../migrations/tests}/test.sql |
362 | 376 | log info "Migrations tests completed successfully"
|
363 | 377 | '';
|
| 378 | + }; |
364 | 379 | in
|
365 | 380 | {
|
366 |
| - psql_15 = makeCheckHarness self'.packages."psql_15/bin"; |
367 |
| - psql_17 = makeCheckHarness self'.packages."psql_17/bin"; |
368 |
| - psql_orioledb-17 = makeCheckHarness self'.packages."psql_orioledb-17/bin"; |
| 381 | + psql_15 = pkgs.runCommand "run-check-harness-psql-15" { } ( |
| 382 | + lib.getExe (makeCheckHarness self'.packages."psql_15/bin") |
| 383 | + ); |
| 384 | + psql_17 = pkgs.runCommand "run-check-harness-psql-17" { } ( |
| 385 | + lib.getExe (makeCheckHarness self'.packages."psql_17/bin") |
| 386 | + ); |
| 387 | + psql_orioledb-17 = pkgs.runCommand "run-check-harness-psql-orioledb-17" { } ( |
| 388 | + lib.getExe (makeCheckHarness self'.packages."psql_orioledb-17/bin") |
| 389 | + ); |
369 | 390 | inherit (self'.packages)
|
370 | 391 | wal-g-2
|
371 | 392 | wal-g-3
|
|
0 commit comments