Skip to content

Commit

Permalink
fix(mssql): use glob to find mssql-tools folder since it moves (#685)
Browse files Browse the repository at this point in the history
fix #666
  • Loading branch information
alexanderankin authored Aug 16, 2024
1 parent 925329d commit 4912725
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/testcontainers/core/container.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion modules/mssql/testcontainers/mssql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 10 additions & 6 deletions modules/mssql/tests/test_mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 4912725

Please sign in to comment.