diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 0000000..2b7b46f --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,6 @@ +mariadb: + image: mcp/mariadb + environment: + DB_ROOT_PASSWORD: r00tme + ports: + - 33306:3306 diff --git a/tests/test_mariadb.py b/tests/test_mariadb.py new file mode 100644 index 0000000..7d46e01 --- /dev/null +++ b/tests/test_mariadb.py @@ -0,0 +1,46 @@ +from subprocess import check_call +import time +import docker +import pytest + + +@pytest.fixture(scope='module') +def cli(request): + return docker.Client() + + +@pytest.fixture(scope='module') +def container(cli): + return cli.containers( + filters={"label": "com.docker.compose.service=mariadb"})[0] + + +def setup_module(module): + check_call(['docker-compose', 'up', '-d']) + time.sleep(30) + + +def teardown_module(module): + check_call(['docker-compose', 'down']) + + +def test_mysql_check_mysqld(cli, container): + res = cli.exec_create(container['Id'], "pgrep mysql") + cli.exec_start(res) + assert cli.exec_inspect(res)['ExitCode'] == 0 + + +def test_mysql_is_running(): + cmd = ['nc', '-z', '-v', '-w5', '127.0.0.1', '33306'] + check_call(cmd) + + +def test_mysql_is_accessible(cli, container): + cmd = ("bash -c 'mysql -Ns -h127.0.0.1 -uroot -p$DB_ROOT_PASSWORD" + " -e \"SHOW DATABASES\"'") + res = cli.exec_create(container['Id'], cmd) + out = cli.exec_start(res) + assert cli.exec_inspect(res)['ExitCode'] == 0 + out = filter(bool, out.split('\n')) + assert set(out) == \ + set(['information_schema', 'mysql', 'performance_schema']) diff --git a/tox.ini b/tox.ini index 4e6bef6..02025d0 100644 --- a/tox.ini +++ b/tox.ini @@ -15,3 +15,12 @@ commands = commands = {toxinidir}/tools/run-check-docker-syntax.sh +[testenv:py27] +deps = + docker-py + docker-compose + pytest +changedir={toxinidir}/tests +commands = + py.test -vv {posargs} +