|
2 | 2 | from pathlib import Path |
3 | 3 | from re import split |
4 | 4 | from time import sleep |
5 | | -from typing import Union |
| 5 | +from typing import Union, Optional |
6 | 6 | from urllib.request import urlopen, Request |
7 | 7 |
|
8 | 8 | import pytest |
@@ -352,3 +352,27 @@ def fetch(req: Union[Request, str]): |
352 | 352 | if 200 < res.getcode() >= 400: |
353 | 353 | raise Exception(f"HTTP Error: {res.getcode()} - {res.reason}: {body}") |
354 | 354 | return res.getcode(), body |
| 355 | + |
| 356 | + |
| 357 | +@pytest.mark.parametrize( |
| 358 | + argnames=["profiles", "running", "not_running"], |
| 359 | + argvalues=[ |
| 360 | + pytest.param(None, ["runs-always"], ["runs-profile-a", "runs-profile-b"], id="default"), |
| 361 | + pytest.param( |
| 362 | + ["profile-a"], ["runs-always", "runs-profile-a"], ["runs-profile-b"], id="one-additional-profile-via-str" |
| 363 | + ), |
| 364 | + pytest.param( |
| 365 | + ["profile-a", "profile-b"], |
| 366 | + ["runs-always", "runs-profile-a", "runs-profile-b"], |
| 367 | + [], |
| 368 | + id="all-profiles-explicitly", |
| 369 | + ), |
| 370 | + ], |
| 371 | +) |
| 372 | +def test_compose_profile_support(profiles: Optional[list[str]], running: list[str], not_running: list[str]): |
| 373 | + with DockerCompose(context=FIXTURES / "profile_support", profiles=profiles) as compose: |
| 374 | + for service in running: |
| 375 | + assert compose.get_container(service) is not None |
| 376 | + for service in not_running: |
| 377 | + with pytest.raises(ContainerIsNotRunning): |
| 378 | + compose.get_container(service) |
0 commit comments