Skip to content

Commit

Permalink
Update tests with modern tags for mysql. Support more ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
santi committed Apr 3, 2024
1 parent 68de4ba commit f63d3c4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions modules/mysql/tests/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@
from testcontainers.mysql import MySqlContainer


@pytest.mark.skipif(is_arm(), reason="mysql container not available for ARM")
def test_docker_run_mysql():
config = MySqlContainer("mysql:5.7.17")
config = MySqlContainer("mysql:8.3.0")
with config as mysql:
engine = sqlalchemy.create_engine(mysql.get_connection_url())
with engine.begin() as connection:
result = connection.execute(sqlalchemy.text("select version()"))
for row in result:
assert row[0].startswith("5.7.17")
assert row[0].startswith("8.3.0")


@pytest.mark.skipif(is_arm(), reason="mysql container not available for ARM")
def test_docker_run_mysql_8():
config = MySqlContainer("mysql:8")
def test_docker_run_legacy_mysql():
config = MySqlContainer("mysql:5.7.44")
with config as mysql:
engine = sqlalchemy.create_engine(mysql.get_connection_url())
with engine.begin() as connection:
result = connection.execute(sqlalchemy.text("select version()"))
for row in result:
assert row[0].startswith("8")
assert row[0].startswith("5.7.17")


def test_docker_run_mariadb():
with MySqlContainer("mariadb:10.6.5").maybe_emulate_amd64() as mariadb:
@pytest.mark.parametrize("version", ["11.3.2", "10.11.7"])
def test_docker_run_mariadb(version: str):
with MySqlContainer(f"mariadb:{version}") as mariadb:
engine = sqlalchemy.create_engine(mariadb.get_connection_url())
with engine.begin() as connection:
result = connection.execute(sqlalchemy.text("select version()"))
for row in result:
assert row[0].startswith("10.6.5")
assert row[0].startswith(version)


def test_docker_env_variables():
with mock.patch.dict("os.environ", MYSQL_USER="demo", MYSQL_DATABASE="custom_db"), MySqlContainer(
"mariadb:10.6.5"
).with_bind_ports(3306, 32785).maybe_emulate_amd64() as container:
).with_bind_ports(3306, 32785) as container:
url = container.get_connection_url()
pattern = r"mysql\+pymysql:\/\/demo:test@[\w,.]+:(3306|32785)\/custom_db"
assert re.match(pattern, url)

0 comments on commit f63d3c4

Please sign in to comment.