Skip to content

Commit

Permalink
Fix connection string, unset PG env vars in tests
Browse files Browse the repository at this point in the history
There were tests failing when running under the windows-latest
environment in GitHub Actions. This is due to PGUSER and PGPASSWORD
being set as part of he image build (https://github.com/actions/runner-images/blob/870d08d9cbff9a9a2b0e805c7e41e5238c184bf0/images/windows/scripts/build/Install-PostgreSQL.ps1#L11-L12).
This change explicitly unsets these environment variables in the tests
to avoid failures in that environment.
  • Loading branch information
lossyrob committed Sep 28, 2024
1 parent 67f15c2 commit c88bc86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def postgres_unit_test_env(monkeypatch, exclude_list, override_env_param_dict):
if override_env_param_dict is None:
override_env_param_dict = {}

env_vars = {"POSTGRES_CONNECTION_STRING": "host=localhost port=5432 dbname=postgres user=postgres password=example"}
env_vars = {"POSTGRES_CONNECTION_STRING": "host=localhost port=5432 dbname=postgres user=testuser password=example"}

env_vars.update(override_env_param_dict)

Expand Down
21 changes: 18 additions & 3 deletions python/tests/unit/connectors/memory/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,16 @@ async def test_get_records(vector_store: PostgresStore, mock_cursor: Mock) -> No
# Test settings


def test_settings_connection_string() -> None:
settings = PostgresSettings(connection_string="postgresql://user:password@localhost:5432/dbname")
def test_settings_connection_string(monkeypatch) -> None:
monkeypatch.delenv("PGHOST", raising=False)
monkeypatch.delenv("PGPORT", raising=False)
monkeypatch.delenv("PGDATABASE", raising=False)
monkeypatch.delenv("PGUSER", raising=False)
monkeypatch.delenv("PGPASSWORD", raising=False)

settings = PostgresSettings(connection_string="host=localhost port=5432 dbname=dbname user=user password=password")
conn_info = settings.get_connection_args()

assert conn_info["host"] == "localhost"
assert conn_info["port"] == 5432
assert conn_info["dbname"] == "dbname"
Expand All @@ -259,7 +266,15 @@ def test_settings_connection_string() -> None:


def test_settings_env_connection_string(monkeypatch) -> None:
monkeypatch.setenv("POSTGRES_CONNECTION_STRING", "postgresql://user:password@localhost:5432/dbname")
monkeypatch.delenv("PGHOST", raising=False)
monkeypatch.delenv("PGPORT", raising=False)
monkeypatch.delenv("PGDATABASE", raising=False)
monkeypatch.delenv("PGUSER", raising=False)
monkeypatch.delenv("PGPASSWORD", raising=False)

monkeypatch.setenv(
"POSTGRES_CONNECTION_STRING", "host=localhost port=5432 dbname=dbname user=user password=password"
)

settings = PostgresSettings()
conn_info = settings.get_connection_args()
Expand Down

0 comments on commit c88bc86

Please sign in to comment.