Skip to content

Commit e1397d9

Browse files
committed
test(config): add unit tests for valkey_url configuration logic
- Introduced new unit tests for the valkey_url property in the configuration settings, covering various scenarios including explicit VALKEY_URL usage, handling of empty values, and construction from host/port/db components. - Enhanced test coverage to ensure correct behavior when VALKEY_PASSWORD is set, verifying that the valkey_url includes authentication details. - These additions improve the reliability of configuration handling related to valkey connections.
1 parent a362839 commit e1397d9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/shared/test_config_settings.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,43 @@ def test_config_get_database_url() -> None:
9898
assert c.get_database_url() == c.database_url == "postgresql://x:y@h:5/db"
9999

100100

101+
def test_config_valkey_url_uses_explicit_valkey_url() -> None:
102+
"""When VALKEY_URL is set, valkey_url returns it unchanged."""
103+
c = _config(VALKEY_URL="valkey://custom:6379/1")
104+
assert c.valkey_url == "valkey://custom:6379/1"
105+
106+
107+
def test_config_valkey_url_empty_when_valkey_host_empty() -> None:
108+
"""When VALKEY_URL is empty and VALKEY_HOST is empty, valkey_url is empty."""
109+
c = _config(VALKEY_URL="", VALKEY_HOST="")
110+
assert c.valkey_url == ""
111+
112+
113+
def test_config_valkey_url_builds_from_components() -> None:
114+
"""When VALKEY_URL is empty and VALKEY_HOST set, valkey_url is built from host/port/db."""
115+
c = _config(
116+
VALKEY_URL="",
117+
VALKEY_HOST="cache.example.com",
118+
VALKEY_PORT=6379,
119+
VALKEY_DB=0,
120+
VALKEY_PASSWORD="",
121+
)
122+
assert c.valkey_url == "valkey://cache.example.com:6379/0"
123+
124+
125+
def test_config_valkey_url_includes_password_when_set() -> None:
126+
"""When VALKEY_PASSWORD is set, valkey_url includes auth and starts with valkey://."""
127+
c = _config(
128+
VALKEY_URL="",
129+
VALKEY_HOST="localhost",
130+
VALKEY_PORT=6379,
131+
VALKEY_DB=0,
132+
VALKEY_PASSWORD="secret",
133+
)
134+
assert c.valkey_url.startswith("valkey://")
135+
assert "localhost" in c.valkey_url
136+
137+
101138
def test_config_get_github_private_key_empty() -> None:
102139
"""get_github_private_key returns empty string when GITHUB_PRIVATE_KEY is empty."""
103140
c = _config(

0 commit comments

Comments
 (0)