| 1 |
|
| 2 |
|
| 3 |
import os |
| 4 |
import unittest |
| 5 |
|
| 6 |
from packaging import version |
| 7 |
from parameterized import parameterized |
| 8 |
|
| 9 |
from tests.integration.test_utils import RunSubprocessMixin |
| 10 |
from tests.integration.test_utils import get_podman_version |
| 11 |
from tests.integration.test_utils import podman_compose_path |
| 12 |
from tests.integration.test_utils import test_path |
| 13 |
|
| 14 |
|
| 15 |
def compose_yaml_path() -> str: |
| 16 |
return os.path.join(os.path.join(test_path(), "nets_test3"), "docker-compose.yml") |
| 17 |
|
| 18 |
|
| 19 |
@unittest.skipIf(get_podman_version() >= version.parse("5.0.0"), "Breaks as of podman-5.4.2.") |
| 20 |
class TestComposeNetsTest3(unittest.TestCase, RunSubprocessMixin): |
| 21 |
|
| 22 |
@parameterized.expand([ |
| 23 |
("nets_test3_web2_1", "web3", b"test3", 0), |
| 24 |
("nets_test3_web2_1", "alias11", b"test3", 0), |
| 25 |
("nets_test3_web2_1", "alias12", b"test3", 0), |
| 26 |
("nets_test3_web2_1", "alias21", b"test3", 0), |
| 27 |
("nets_test3_web1_1", "web3", b"test3", 0), |
| 28 |
("nets_test3_web1_1", "alias11", b"test3", 0), |
| 29 |
("nets_test3_web1_1", "alias12", b"test3", 0), |
| 30 |
|
| 31 |
("nets_test3_web1_1", "alias21", b"", 1), |
| 32 |
]) |
| 33 |
def test_nets_test3( |
| 34 |
self, |
| 35 |
container_name: str, |
| 36 |
network_alias_name: str, |
| 37 |
expected_text: bytes, |
| 38 |
expected_returncode: int, |
| 39 |
) -> None: |
| 40 |
try: |
| 41 |
self.run_subprocess_assert_returncode( |
| 42 |
[ |
| 43 |
podman_compose_path(), |
| 44 |
"-f", |
| 45 |
compose_yaml_path(), |
| 46 |
"up", |
| 47 |
"-d", |
| 48 |
], |
| 49 |
) |
| 50 |
|
| 51 |
cmd = [ |
| 52 |
"podman", |
| 53 |
"exec", |
| 54 |
"-it", |
| 55 |
f"{container_name}", |
| 56 |
"/bin/busybox", |
| 57 |
"wget", |
| 58 |
"-O", |
| 59 |
"-", |
| 60 |
"-o", |
| 61 |
"/dev/null", |
| 62 |
f"http://{network_alias_name}:8001/index.txt", |
| 63 |
] |
| 64 |
out, _, returncode = self.run_subprocess(cmd) |
| 65 |
self.assertEqual(expected_returncode, returncode) |
| 66 |
self.assertEqual(expected_text, out.strip()) |
| 67 |
finally: |
| 68 |
self.run_subprocess_assert_returncode([ |
| 69 |
podman_compose_path(), |
| 70 |
"-f", |
| 71 |
compose_yaml_path(), |
| 72 |
"down", |
| 73 |
"-t", |
| 74 |
"0", |
| 75 |
]) |