-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_image.py
More file actions
26 lines (20 loc) · 797 Bytes
/
test_image.py
File metadata and controls
26 lines (20 loc) · 797 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
import pytest
import subprocess
import testinfra
@pytest.fixture(scope="session")
def host(request):
image = request.config.getoption("--image")
# build local ./Dockerfile
# subprocess.check_call(['docker', 'build', '-t', 'myimage', '.'])
# run a container
docker_id = subprocess.check_output(["docker", "run", "-d", image]).decode().strip()
# return a testinfra connection to the container
yield testinfra.get_host("docker://" + docker_id)
# at the end of the test suite, destroy the container
subprocess.check_call(["docker", "rm", "-f", docker_id])
def test_dig_package(host):
"Check dig is installed"
assert host.package("bind-tools").is_installed
def test_dig_works(host):
"Check dig works"
assert host.run("dig localhost").succeeded