diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index e9415441a..9211b13bf 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -1,7 +1,7 @@ import contextlib from platform import system from socket import socket -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, Union import docker.errors from docker import version @@ -186,7 +186,7 @@ def get_logs(self) -> tuple[bytes, bytes]: raise ContainerStartException("Container should be started before getting logs") return self._container.logs(stderr=False), self._container.logs(stdout=False) - def exec(self, command) -> tuple[int, bytes]: + def exec(self, command: Union[str, list[str]]) -> tuple[int, bytes]: if not self._container: raise ContainerStartException("Container should be started before executing a command") return self._container.exec_run(command) diff --git a/modules/mssql/testcontainers/mssql/__init__.py b/modules/mssql/testcontainers/mssql/__init__.py index 6cee36813..e13f9cf0f 100644 --- a/modules/mssql/testcontainers/mssql/__init__.py +++ b/modules/mssql/testcontainers/mssql/__init__.py @@ -52,7 +52,9 @@ def _configure(self) -> None: @wait_container_is_ready(AssertionError) def _connect(self) -> None: - status, _ = self.exec(f"/opt/mssql-tools/bin/sqlcmd -U {self.username} -P {self.password} -Q 'SELECT 1'") + status, _ = self.exec( + ["bash", "-c", '/opt/mssql-tools*/bin/sqlcmd -U "$SQLSERVER_USER" -P "$SA_PASSWORD" -Q \'SELECT 1\' -C'] + ) assert status == 0, "Cannot run 'SELECT 1': container is not ready" def get_connection_url(self) -> str: diff --git a/modules/mssql/tests/test_mssql.py b/modules/mssql/tests/test_mssql.py index f7aabd3af..c8c6d5e1a 100644 --- a/modules/mssql/tests/test_mssql.py +++ b/modules/mssql/tests/test_mssql.py @@ -25,13 +25,17 @@ def test_docker_run_azure_sql_edge(): assert row[0] == "MSSQLSERVER" -# This is a feature in the generic DbContainer class +def test_microsoft_changes_the_mssql_tools_folder_name(): + with SqlServerContainer("mcr.microsoft.com/mssql/server:2019-latest") as mssql: + engine = sqlalchemy.create_engine(mssql.get_connection_url()) + with engine.begin() as connection: + result = connection.execute(sqlalchemy.text("select @@servicename")) + for row in result: + assert row[0] == "MSSQLSERVER" + + +# This is a feature in the generic DbContainer class, # but it can't be tested on its own -# so is tested in various database modules: -# - mysql / mariadb -# - postgresql -# - sqlserver -# - mongodb def test_quoted_password(): user = "SA" # spaces seem to cause issues?