Skip to content

Commit 4912725

Browse files
fix(mssql): use glob to find mssql-tools folder since it moves (#685)
fix #666
1 parent 925329d commit 4912725

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

core/testcontainers/core/container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import contextlib
22
from platform import system
33
from socket import socket
4-
from typing import TYPE_CHECKING, Optional
4+
from typing import TYPE_CHECKING, Optional, Union
55

66
import docker.errors
77
from docker import version
@@ -186,7 +186,7 @@ def get_logs(self) -> tuple[bytes, bytes]:
186186
raise ContainerStartException("Container should be started before getting logs")
187187
return self._container.logs(stderr=False), self._container.logs(stdout=False)
188188

189-
def exec(self, command) -> tuple[int, bytes]:
189+
def exec(self, command: Union[str, list[str]]) -> tuple[int, bytes]:
190190
if not self._container:
191191
raise ContainerStartException("Container should be started before executing a command")
192192
return self._container.exec_run(command)

modules/mssql/testcontainers/mssql/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def _configure(self) -> None:
5252

5353
@wait_container_is_ready(AssertionError)
5454
def _connect(self) -> None:
55-
status, _ = self.exec(f"/opt/mssql-tools/bin/sqlcmd -U {self.username} -P {self.password} -Q 'SELECT 1'")
55+
status, _ = self.exec(
56+
["bash", "-c", '/opt/mssql-tools*/bin/sqlcmd -U "$SQLSERVER_USER" -P "$SA_PASSWORD" -Q \'SELECT 1\' -C']
57+
)
5658
assert status == 0, "Cannot run 'SELECT 1': container is not ready"
5759

5860
def get_connection_url(self) -> str:

modules/mssql/tests/test_mssql.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ def test_docker_run_azure_sql_edge():
2525
assert row[0] == "MSSQLSERVER"
2626

2727

28-
# This is a feature in the generic DbContainer class
28+
def test_microsoft_changes_the_mssql_tools_folder_name():
29+
with SqlServerContainer("mcr.microsoft.com/mssql/server:2019-latest") as mssql:
30+
engine = sqlalchemy.create_engine(mssql.get_connection_url())
31+
with engine.begin() as connection:
32+
result = connection.execute(sqlalchemy.text("select @@servicename"))
33+
for row in result:
34+
assert row[0] == "MSSQLSERVER"
35+
36+
37+
# This is a feature in the generic DbContainer class,
2938
# but it can't be tested on its own
30-
# so is tested in various database modules:
31-
# - mysql / mariadb
32-
# - postgresql
33-
# - sqlserver
34-
# - mongodb
3539
def test_quoted_password():
3640
user = "SA"
3741
# spaces seem to cause issues?

0 commit comments

Comments
 (0)