Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Standardize configuration and readiness steps in container lifecycle #527

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fc7c466
Include configuration and waiting hooks in base DockerContainer class
santi Apr 2, 2024
2578a97
Inherit directly from DockerContainer in ArangoDB module
santi Apr 2, 2024
fa0d34a
Use new _wait_until_ready hook in Azureite module
santi Apr 2, 2024
482df60
Use new _wait_until_ready hook in Cassandra module
santi Apr 2, 2024
9437d89
Add http waiting strategy for basic HTTP endpoint status codes
santi Apr 2, 2024
d4a0612
Use new _wait_until_ready hook in ChromaDB module
santi Apr 2, 2024
b7e52ba
Create utility for generating db client compatible connection strings
santi Apr 3, 2024
6964d3e
Use new _wait_until_ready hook in clickhouse module
santi Apr 3, 2024
9e43875
Use new _wait_until_ready hook in elasticsearch module
santi Apr 3, 2024
1b3aebc
Use new _wait_until_ready hook in google module
santi Apr 3, 2024
abbbf7d
Fix case for connection_string without username or password
santi Apr 3, 2024
09c10ba
Use new _wait_until_ready hook in influxdb module
santi Apr 3, 2024
bea1372
Use new _wait_until_ready hook in k3s module
santi Apr 3, 2024
d19f6c9
Use new _wait_until_ready hook in kafka module
santi Apr 3, 2024
124727c
Use new _wait_until_ready hook in keycloak module
santi Apr 3, 2024
1831366
Use new _wait_until_ready hook in localstack module
santi Apr 3, 2024
0688858
Use new _wait_until_ready hook in minio module
santi Apr 3, 2024
e5afe88
Use new _wait_until_ready hook in mongodb module
santi Apr 3, 2024
20aead1
Reorder imports for linting
santi Apr 3, 2024
00b2e7f
Use new _wait_until_ready hook in mssql module
santi Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use new _wait_until_ready hook in google module
  • Loading branch information
santi committed Apr 3, 2024
commit 1b3aebc6c89e370dfbe07b83971afa6ea1d848d5
6 changes: 4 additions & 2 deletions modules/google/testcontainers/google/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .datastore import DatastoreContainer # noqa: F401
from .pubsub import PubSubContainer # noqa: F401
from .datastore import DatastoreContainer
from .pubsub import PubSubContainer

__all__ = ["DatastoreContainer", "PubSubContainer"]
10 changes: 7 additions & 3 deletions modules/google/testcontainers/google/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import os
from unittest.mock import patch

from typing_extensions import override

from google.cloud import datastore
from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_for_logs
Expand All @@ -32,8 +34,7 @@ class DatastoreContainer(DockerContainer):

>>> from testcontainers.google import DatastoreContainer

>>> config = DatastoreContainer()
>>> with config as datastore:
>>> with DatastoreContainer("google/cloud-sdk:471.0.0-emulators") as datastore:
... datastore_client = datastore.get_datastore_client()
"""

Expand All @@ -56,7 +57,6 @@ def get_datastore_emulator_host(self) -> str:
return f"{self.get_container_host_ip()}:{self.get_exposed_port(self.port)}"

def get_datastore_client(self, **kwargs) -> datastore.Client:
wait_for_logs(self, "Dev App Server is now running.", timeout=30.0)
env_vars = {
"DATASTORE_DATASET": self.project,
"DATASTORE_EMULATOR_HOST": self.get_datastore_emulator_host(),
Expand All @@ -66,3 +66,7 @@ def get_datastore_client(self, **kwargs) -> datastore.Client:
}
with patch.dict(os.environ, env_vars):
return datastore.Client(**kwargs)

@override
def _wait_until_ready(self) -> None:
wait_for_logs(self, "Dev App Server is now running.", timeout=30.0)
3 changes: 1 addition & 2 deletions modules/google/testcontainers/google/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class PubSubContainer(DockerContainer):

>>> from testcontainers.google import PubSubContainer

>>> config = PubSubContainer()
>>> with config as pubsub:
>>> with PubSubContainer("google/cloud-sdk:471.0.0-emulators") as pubsub:
... publisher = pubsub.get_publisher_client()
... topic_path = publisher.topic_path(pubsub.project, "my-topic")
... topic = publisher.create_topic(name=topic_path)
Expand Down
9 changes: 4 additions & 5 deletions modules/google/tests/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


def test_pubsub_container():
pubsub: PubSubContainer
with PubSubContainer() as pubsub:
with PubSubContainer("google/cloud-sdk:471.0.0-emulators") as pubsub:
wait_for_logs(pubsub, r"Server started, listening on \d+", timeout=60)
# Create a new topic
publisher = pubsub.get_publisher_client()
Expand All @@ -32,7 +31,7 @@ def test_pubsub_container():

def test_datastore_container_creation():
# Initialize the Datastore emulator container
with DatastoreContainer() as datastore:
with DatastoreContainer("google/cloud-sdk:471.0.0-emulators") as datastore:
# Obtain a datastore client configured to connect to the emulator
client = datastore.get_datastore_client()

Expand All @@ -54,7 +53,7 @@ def test_datastore_container_creation():

def test_datastore_container_isolation():
# Initialize the Datastore emulator container
with DatastoreContainer() as datastore:
with DatastoreContainer("google/cloud-sdk:471.0.0-emulators") as datastore:
# Obtain a datastore client configured to connect to the emulator
client = datastore.get_datastore_client()

Expand All @@ -67,7 +66,7 @@ def test_datastore_container_isolation():
client.put(entity)

# Create a second container and try to fetch the entity to makesure its a different container
with DatastoreContainer() as datastore2:
with DatastoreContainer("google/cloud-sdk:471.0.0-emulators") as datastore2:
assert (
datastore.get_datastore_emulator_host() != datastore2.get_datastore_emulator_host()
), "Datastore containers use the same port."
Expand Down