Skip to content

Commit

Permalink
chore: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abhvsn committed Sep 30, 2024
1 parent a1f8630 commit 69e64cf
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions deploy/docker/tests/test_pg-utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -e

# Include the script to be tested
source /Users/appsmith/Work/appsmith-ce/deploy/docker/fs/opt/appsmith/pg-utils.sh

# Test extract_postgres_db_params function
test_extract_postgres_db_params_valid_db_string() {
local conn_string="postgresql://user:password@localhost:5432/dbname"
extract_postgres_db_params "$conn_string"

if [ "$PG_DB_USER" != "user" ] || [ "$PG_DB_PASSWORD" != "password" ] || [ "$PG_DB_HOST" != "localhost" ] || [ "$PG_DB_PORT" != "5432" ] || [ "$PG_DB_NAME" != "dbname" ]; then
echo "Test failed: test_extract_postgres_db_params_valid_db_string did not extract parameters correctly"
echo_params
exit 1
fi

echo "Test passed: test_extract_postgres_db_params_valid_db_string"
}

test_extract_postgres_db_params_empty_dbname() {
local conn_string="postgresql://user:password@localhost:5432"
extract_postgres_db_params "$conn_string"

if [ "$PG_DB_USER" != "user" ] || [ "$PG_DB_PASSWORD" != "password" ] || [ "$PG_DB_HOST" != "localhost" ] || [ "$PG_DB_PORT" != "5432" ] || [ "$PG_DB_NAME" != "" ]; then
echo "Test failed: test_extract_postgres_db_params_empty_dbname did not extract parameters correctly"
echo_params
exit 1
fi

echo "Test passed: test_extract_postgres_db_params_empty_dbname"
}

test_extract_postgres_db_params_with_spaces() {
local conn_string="postgresql://user:p a s s w o r d@localhost:5432/db_name"
extract_postgres_db_params "$conn_string"

if [ "$PG_DB_USER" != "user" ] || [ "$PG_DB_PASSWORD" != "p%20a%20s%20s%20w%20o%20r%20d" ] || [ "$PG_DB_HOST" != "localhost" ] || [ "$PG_DB_PORT" != "5432" ] || [ "$PG_DB_NAME" != "db_name" ]; then
echo "Test failed: test_extract_postgres_db_params_with_spaces did not extract parameters correctly"
echo_params
exit 1
fi

echo "Test passed: test_extract_postgres_db_params_with_spaces"
}

echo_params() {
echo "PG_DB_USER: $PG_DB_USER"
echo "PG_DB_PASSWORD: $PG_DB_PASSWORD"
echo "PG_DB_HOST: $PG_DB_HOST"
echo "PG_DB_PORT: $PG_DB_PORT"
echo "PG_DB_NAME: $PG_DB_NAME"
}

# Run tests
test_extract_postgres_db_params_valid_db_string
test_extract_postgres_db_params_empty_dbname
test_extract_postgres_db_params_with_spaces

echo "All Tests Pass!"

0 comments on commit 69e64cf

Please sign in to comment.