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