Skip to content

Commit

Permalink
pants-plugins/uses_services: Add env_vars_hint message
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Nov 17, 2024
1 parent f39c755 commit 1fa335f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 5 additions & 0 deletions pants-plugins/uses_services/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ServiceSpecificMessages:

service_start_cmd_generic: str

env_vars_hint: str = ""


class ServiceMissingError(Exception):
"""Error raised when a test uses a service but that service is missing."""
Expand Down Expand Up @@ -162,6 +164,9 @@ def generate(
"""
)

if messages.env_vars_hint:
instructions += f"\n\n{messages.env_vars_hint}"

return cls(
service=service,
platform=platform,
Expand Down
22 changes: 9 additions & 13 deletions pants-plugins/uses_services/redis_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ async def redis_is_running(
if is_running:
return RedisIsRunning()

env_vars_hint = dedent(
"""
You can also export the ST2TESTS_REDIS_HOST and ST2TESTS_REDIS_PORT
env vars to automatically use any redis host, local or remote,
while running unit and integration tests.
"""
)
# redis is not running, so raise an error with instructions.
raise ServiceMissingError.generate(
platform=platform,
Expand All @@ -162,21 +155,24 @@ async def redis_is_running(
"""\
sudo yum -y install redis
# Don't forget to start redis.
"""
)
+ env_vars_hint,
),
service_start_cmd_deb="systemctl start redis",
not_installed_clause_deb="this is one way to install it:",
install_instructions_deb=dedent(
"""\
sudo apt-get install -y mongodb redis
# Don't forget to start redis.
"""
)
+ env_vars_hint,
),
service_start_cmd_generic="systemctl start redis",
env_vars_hint=dedent(
"""\
You can also export the ST2TESTS_REDIS_HOST and ST2TESTS_REDIS_PORT
env vars to automatically use any redis host, local or remote,
while running unit and integration tests.
"""
),
),
)

Expand Down

0 comments on commit 1fa335f

Please sign in to comment.