forked from 1NF053C/penguin-pie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dockerinfra.py
More file actions
29 lines (24 loc) · 978 Bytes
/
test_dockerinfra.py
File metadata and controls
29 lines (24 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pytest
import subprocess
import testinfra
# scope='session' uses the same container for all the tests;
# scope='function' uses a new container per test function.
@pytest.fixture(scope="session")
def host(request):
# build local ./Dockerfile
subprocess.check_call(["docker", "build", "-t", "myimage", "."])
# run a container
docker_id = (
subprocess.check_output(["docker", "run", "-d", "myimage"]).decode().strip()
)
# return a testinfra connection to the container
yield testinfra.get_host("docker://" + docker_id)
# at the end of the test suite, destroy container and delete image
subprocess.check_call(["docker", "rm", "-f", docker_id])
subprocess.check_call(["docker", "image", "remove", "myimage"])
def test_myimage(host):
# 'host' now binds to the container
assert host.exists("python3")
assert host.exists("python")
assert host.file("/app/main.py").exists
assert host.file("/app/lib").exists