@@ -11,20 +11,20 @@ echo "============================================="
1111SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
1212INSTALL_SCRIPT=" $SCRIPT_DIR /../install.sh"
1313
14- # Check if PG0_BINARY_PATH is set (local binary to test)
15- VOLUME_ARGS=" "
16- BINARY_ENV=" "
17- if [ -n " ${PG0_BINARY_PATH:- } " ]; then
18- echo " Using local binary: $PG0_BINARY_PATH "
19- VOLUME_ARGS=" -v $PG0_BINARY_PATH :/tmp/pg0-binary:ro"
20- BINARY_ENV=" -e PG0_BINARY_URL=file:///tmp/pg0-binary"
14+ # PG0_BINARY_PATH is required - this test must use a binary built from source
15+ # (with the shared library detection code), not the released binary
16+ if [ -z " ${PG0_BINARY_PATH:- } " ]; then
17+ echo " ERROR: PG0_BINARY_PATH must be set to a Linux binary built from this branch"
18+ exit 1
2119fi
2220
23- docker run --rm --platform=linux/amd64 \
24- $BINARY_ENV \
25- -v " $INSTALL_SCRIPT :/tmp/install.sh:ro" \
26- $VOLUME_ARGS \
27- python:3.11-slim bash -c '
21+ echo " Using local binary: $PG0_BINARY_PATH "
22+
23+ # Create a temporary test script to run inside the container
24+ # This avoids nested heredoc quoting issues
25+ TEMP_SCRIPT=$( mktemp)
26+ cat > " $TEMP_SCRIPT " << 'INNERSCRIPT '
27+ #!/bin/bash
2828set -e
2929
3030echo "=== System Info ==="
@@ -43,69 +43,61 @@ useradd -m -s /bin/bash pguser
4343echo "pguser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
4444
4545echo ""
46- echo "=== Copying local install.sh ==="
47- cp /tmp/install.sh /usr/local/bin/install.sh
48- chmod 755 /usr/local/bin/install.sh
46+ echo "=== Installing pg0 from local binary ==="
47+ cp /tmp/pg0-binary /usr/local/bin/pg0
48+ chmod 755 /usr/local/bin/pg0
4949
5050echo ""
51- echo "=== Phase 1: Install pg0 and do initial extraction ==="
52- su - pguser << EOF
51+ echo "=== Phase 1: Initial extraction with all deps present ==="
52+ su -s /bin/bash - pguser -c '
5353set -e
54- export PG0_BINARY_URL="${PG0_BINARY_URL}"
55-
56- echo "=== Installing pg0 ==="
57- bash /usr/local/bin/install.sh
58- export PATH="\$HOME/.local/bin:\$PATH"
54+ export PATH="/usr/local/bin:$PATH"
5955
60- echo ""
6156echo "=== Starting PostgreSQL (initial extraction) ==="
6257pg0 start
6358sleep 3
6459
65- echo ""
6660echo "=== Stopping PostgreSQL ==="
6761pg0 stop
6862sleep 1
6963
70- echo ""
7164echo "=== Removing extracted installation to force re-extraction ==="
7265rm -rf ~/.pg0/installation
7366echo "Installation directory cleared."
74- EOF
67+ '
7568
7669echo ""
7770echo "=== Phase 2: Remove libxml2 to simulate missing library ==="
7871apt-get remove -y libxml2 2>&1 | tail -3
7972
8073echo ""
8174echo "=== Phase 3: Verify pg0 detects missing libraries ==="
82- su - pguser << EOF
75+ su -s /bin/bash - pguser -c '
8376set -e
84- export PATH="\$HOME/. local/bin:\ $PATH"
77+ export PATH="/usr/ local/bin:$PATH"
8578
8679echo "=== Starting pg0 (should fail with missing library error) ==="
87- OUTPUT=\$(pg0 start 2>&1 || true)
88- EXIT_CODE=\${PIPESTATUS[0]:-\$?}
89- echo "\$OUTPUT"
80+ OUTPUT=$(pg0 start 2>&1 || true)
81+ echo "$OUTPUT"
9082
9183echo ""
9284echo "=== Checking error message ==="
9385
94- if echo "\ $OUTPUT" | grep -q "missing required system libraries"; then
95- echo "PASS: Found ' missing required system libraries' message"
86+ if echo "$OUTPUT" | grep -q "missing required system libraries"; then
87+ echo "PASS: Found missing required system libraries message"
9688else
9789 echo "FAIL: Missing expected error message about shared libraries"
9890 exit 1
9991fi
10092
101- if echo "\ $OUTPUT" | grep -q "libxml2"; then
102- echo "PASS: Found ' libxml2' in the missing library list"
93+ if echo "$OUTPUT" | grep -qi "libxml2"; then
94+ echo "PASS: Found libxml2 in the missing library list"
10395else
10496 echo "FAIL: Expected libxml2 to be listed as missing"
10597 exit 1
10698fi
10799
108- if echo "\ $OUTPUT" | grep -q "Install the missing libraries"; then
100+ if echo "$OUTPUT" | grep -q "Install the missing libraries"; then
109101 echo "PASS: Found install guidance message"
110102else
111103 echo "FAIL: Missing install guidance"
@@ -116,8 +108,15 @@ echo ""
116108echo "============================================="
117109echo "ALL CHECKS PASSED - Missing libs detected"
118110echo "============================================="
119- EOF
120111'
112+ INNERSCRIPT
113+
114+ docker run --rm --platform=linux/amd64 \
115+ -v " $PG0_BINARY_PATH :/tmp/pg0-binary:ro" \
116+ -v " $TEMP_SCRIPT :/tmp/test_script.sh:ro" \
117+ python:3.11-slim bash /tmp/test_script.sh
118+
119+ rm -f " $TEMP_SCRIPT "
121120
122121echo " "
123122echo " Test completed successfully!"
0 commit comments