Skip to content

Commit cf5c2c3

Browse files
committed
Fix tests and special character username test
Add URI encoding of user and db name in tests that use the connection URI to access a container, test that it works with both spaces and special characters. This is because postgres 18 does not accept spaces in the connection URI but earlier versions do.
1 parent 9965e02 commit cf5c2c3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/run_test

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ function get_ip_from_cid() {
110110
}
111111

112112
function postgresql_cmd() {
113-
docker run --rm -e PGPASSWORD="$PASS" "$IMAGE_NAME" psql -v ON_ERROR_STOP=1 "postgresql://$PGUSER@$CONTAINER_IP:5432/${DB-db}" "$@"
113+
# URI encode the values used inside the connection URI to avoid special
114+
# characters causing the tests using them to fail.
115+
# These tests should not fail because the container is created just fine
116+
# as it uses just environment variables. We need both the creation and
117+
# connection to use the same values, which this use of `jq` ensures.
118+
USERENC=$(jq -rn --arg x "$PGUSER" '$x|@uri')
119+
DBENC=$(jq -rn --arg x "${DB-db}" '$x|@uri')
120+
docker run --rm -e PGPASSWORD="$PASS" "$IMAGE_NAME" psql -v ON_ERROR_STOP=1 "postgresql://$USERENC@$CONTAINER_IP:5432/$DBENC" "$@"
114121
}
115122

116123
function test_connection() {
@@ -648,6 +655,7 @@ VERY_LONG_IDENTIFIER="very_long_identifier_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
648655

649656
assert_container_creation_succeeds -e POSTGRESQL_ADMIN_PASSWORD="the @password" || ret=9
650657
assert_container_creation_succeeds -e POSTGRESQL_PASSWORD="the pass" -e POSTGRESQL_USER="the user" -e POSTGRESQL_DATABASE="the db" || ret=10
658+
assert_container_creation_succeeds -e POSTGRESQL_PASSWORD="the pass" -e POSTGRESQL_USER="the@user" -e POSTGRESQL_DATABASE="the/db" || ret=10
651659

652660
if [ $ret -eq 0 ]; then
653661
echo " Success!"

0 commit comments

Comments
 (0)