Skip to content

Commit

Permalink
fix: get container host addresses from testcontainers
Browse files Browse the repository at this point in the history
Signed-off-by: tokoko <[email protected]>
  • Loading branch information
tokoko committed Feb 11, 2024
1 parent 4e450ad commit 1e3e39b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def create_online_store(self) -> Dict[str, str]:
container=self.container, predicate=log_string_to_wait_for, timeout=10
)
exposed_port = self.container.get_exposed_port("6379")
return {"type": "redis", "connection_string": f"localhost:{exposed_port},db=0"}
container_host = self.container.get_container_host_ip()
return {
"type": "redis",
"connection_string": f"{container_host}:{exposed_port},db=0",
}

def teardown(self):
self.container.stop()
6 changes: 4 additions & 2 deletions sdk/python/tests/unit/test_sql_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ def pg_registry():
)
logger.info("Waited for %s seconds until postgres container was up", waited)
container_port = container.get_exposed_port(5432)
container_host = container.get_container_host_ip()

registry_config = RegistryConfig(
registry_type="sql",
path=f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@127.0.0.1:{container_port}/{POSTGRES_DB}",
path=f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}",
)

yield SqlRegistry(registry_config, "project", None)
Expand Down Expand Up @@ -100,10 +101,11 @@ def mysql_registry():
)
logger.info("Waited for %s seconds until mysql container was up", waited)
container_port = container.get_exposed_port(3306)
container_host = container.get_container_host_ip()

registry_config = RegistryConfig(
registry_type="sql",
path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@127.0.0.1:{container_port}/{POSTGRES_DB}",
path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}",
)

yield SqlRegistry(registry_config, "project", None)
Expand Down

0 comments on commit 1e3e39b

Please sign in to comment.