forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_docker_compose.py
More file actions
55 lines (41 loc) · 1.88 KB
/
Copy pathtest_docker_compose.py
File metadata and controls
55 lines (41 loc) · 1.88 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from testcontainers.compose import DockerCompose
from testcontainers.core.docker_client import DockerClient
from testcontainers.core.exceptions import NoSuchPortExposed
def test_can_spawn_service_via_compose():
with DockerCompose("tests") as compose:
host = compose.get_service_host("hub", 4444)
port = compose.get_service_port("hub", 4444)
assert host == "0.0.0.0"
assert port == "4444"
def test_can_pull_images_before_spawning_service_via_compose():
with DockerCompose("tests", pull=True) as compose:
host = compose.get_service_host("hub", 4444)
port = compose.get_service_port("hub", 4444)
assert host == "0.0.0.0"
assert port == "4444"
def test_can_throw_exception_if_no_port_exposed():
with DockerCompose("tests") as compose:
with pytest.raises(NoSuchPortExposed):
compose.get_service_host("hub", 5555)
def test_compose_wait_for_container_ready():
with DockerCompose("tests") as compose:
docker = DockerClient()
compose.wait_for("http://%s:4444/wd/hub" % docker.host())
def test_can_parse_multiple_compose_files():
with DockerCompose(filepath="tests",
compose_file_name=["docker-compose.yml", "docker-compose-2.yml"]) as compose:
host = compose.get_service_host("mysql", 3306)
port = compose.get_service_port("mysql", 3306)
assert host == "0.0.0.0"
assert port == "3306"
host = compose.get_service_host("hub", 4444)
port = compose.get_service_port("hub", 4444)
assert host == "0.0.0.0"
assert port == "4444"
def test_can_get_logs():
with DockerCompose("tests") as compose:
docker = DockerClient()
compose.wait_for("http://%s:4444/wd/hub" % docker.host())
stdout, stderr = compose.get_logs()
assert stdout, 'There should be something on stdout'