diff --git a/testcontainers/compose.py b/testcontainers/compose.py index b5961aa8..0284634c 100644 --- a/testcontainers/compose.py +++ b/testcontainers/compose.py @@ -186,7 +186,7 @@ def get_service_port(self, service_name, port): str: The mapped port on the host """ - return self._get_service_info(service_name, port)[1] + return self.get_service_info(service_name, port)[1] def get_service_host(self, service_name, port): """ @@ -204,9 +204,24 @@ def get_service_host(self, service_name, port): str: The hostname for the service """ - return self._get_service_info(service_name, port)[0] + return self.get_service_info(service_name, port)[0] - def _get_service_info(self, service, port): + def get_service_info(self, service, port): + """ + Returns the host and the port for one of the services. + + Parameters + ---------- + service: str + Name of the docker compose service + port: int + The internal port to get the host for + + Returns + ------- + (str, str): + The hostname for the service, The port for the service + """ port_cmd = self.docker_compose_command() + ["port", service, str(port)] output = subprocess.check_output(port_cmd, cwd=self.filepath).decode("utf-8") result = str(output).rstrip().split(":") diff --git a/tests/test_core/test_docker_compose.py b/tests/test_core/test_docker_compose.py index ce8ec02c..e93dcac7 100644 --- a/tests/test_core/test_docker_compose.py +++ b/tests/test_core/test_docker_compose.py @@ -64,8 +64,7 @@ def test_can_parse_multiple_compose_files(): assert host == "0.0.0.0" assert port == "3306" - host = compose.get_service_host("hub", 4444) - port = compose.get_service_port("hub", 4444) + host, port = compose.get_service_info("hub", 4444) assert host == "0.0.0.0" assert port == "4444"