Skip to content

Commit 16cbdcd

Browse files
Add documentation and doctest
1 parent 31fd137 commit 16cbdcd

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

testcontainers/minio.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@
66

77

88
class MinioContainer(DockerContainer):
9+
"""
10+
The example below spins up an Minio container and creates a new bucket in it.
11+
Furthermore, it demonstrates how an object is written to this bucket and then subsequently retrieved.
12+
The method :code:`get_client` can be used to create a client for the Minio Python API.
13+
The method :code:`get_config` can be used to retrieve the endpoint, access key
14+
and secret key of the container.
15+
16+
Example
17+
-------
18+
.. doctest::
19+
20+
>>> from testcontainers.minio import MinioContainer
21+
22+
>>> with MinioContainer() as minio:
23+
... client = minio.get_client()
24+
... client.make_bucket("test")
25+
... test_content = b"Hello World"
26+
... client.put_object(
27+
... "test",
28+
... "testfile.txt",
29+
... io.BytesIO(test_content),
30+
... length=len(test_content),
31+
... )
32+
... retrieved_content = client.get_object("test", "testfile.txt").data
33+
"""
34+
935
def __init__(
1036
self,
1137
image="minio/minio:RELEASE.2022-12-02T19-19-22Z",
@@ -14,6 +40,14 @@ def __init__(
1440
secret_key="minioadmin",
1541
**kwargs,
1642
):
43+
"""
44+
Args:
45+
image (str, optional): The Docker image to use for the Minio container.
46+
Defaults to "minio/minio:RELEASE.2022-12-02T19-19-22Z".
47+
port_to_expose (int, optional): The port to expose on the container. Defaults to 9000.
48+
access_key (str, optional): The access key for client connections. Defaults to "minioadmin".
49+
secret_key (str, optional): The secret key for client connections. Defaults to "minioadmin".
50+
"""
1751
super(MinioContainer, self).__init__(image, **kwargs)
1852
self.port_to_expose = port_to_expose
1953
self.access_key = access_key
@@ -42,7 +76,8 @@ def get_client(self, **kwargs) -> Minio:
4276
)
4377

4478
def get_config(self) -> dict:
45-
"""Returns the configuration of the Minio container.
79+
"""This method returns the configuration of the Minio container,
80+
including the endpoint, access key, and secret key.
4681
4782
Returns:
4883
dict: {`endpoint`: str, `access_key`: str, `secret_key`: str}
@@ -57,11 +92,15 @@ def get_config(self) -> dict:
5792

5893
@wait_container_is_ready(ConnectionError)
5994
def _healthcheck(self):
95+
"""This is an internal method used to check if the Minio container
96+
is healthy and ready to receive requests."""
6097
url = f"http://{self.get_config()['endpoint']}/minio/health/live"
6198
response: Response = get(url)
6299
response.raise_for_status()
63100

64101
def start(self):
102+
"""This method starts the Minio container and runs the healthcheck
103+
to verify that the container is ready to use."""
65104
super().start()
66105
self._healthcheck()
67106
return self

0 commit comments

Comments
 (0)