github.com/crowdsecurity/crowdsec@v1.6.1/docker/test/tests/test_hello.py (about) 1 #!/usr/bin/env python 2 3 """ 4 Smoke tests in case docker is not set up correctly or has connection issues. 5 """ 6 7 import subprocess 8 9 import pytest 10 11 pytestmark = pytest.mark.docker 12 13 14 def test_docker_cli_run(): 15 """Test if docker run works from the command line. Capture stdout too""" 16 res = subprocess.run(['docker', 'run', '--rm', 'hello-world'], 17 capture_output=True, text=True) 18 assert 0 == res.returncode 19 assert 'Hello from Docker!' in res.stdout 20 21 22 def test_docker_run(docker_client): 23 """Test if docker run works from the python SDK.""" 24 output = docker_client.containers.run('hello-world', remove=True) 25 lines = output.decode().splitlines() 26 assert "Hello from Docker!" in lines 27 28 29 def test_docker_run_detach(docker_client): 30 """Test with python SDK (async).""" 31 cont = docker_client.containers.run('hello-world', detach=True) 32 assert cont.status == 'created' 33 assert cont.attrs['State']['ExitCode'] == 0 34 lines = cont.logs().decode().splitlines() 35 assert "Hello from Docker!" in lines 36 cont.remove(force=True)