| 1 |
|
| 2 |
|
| 3 |
""" |
| 4 |
test_podman_compose_ports.py |
| 5 |
|
| 6 |
Tests the podman compose port command used to show the host port. |
| 7 |
""" |
| 8 |
|
| 9 |
import os |
| 10 |
import unittest |
| 11 |
|
| 12 |
from tests.integration.test_utils import RunSubprocessMixin |
| 13 |
from tests.integration.test_utils import podman_compose_path |
| 14 |
from tests.integration.test_utils import test_path |
| 15 |
|
| 16 |
|
| 17 |
class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin): |
| 18 |
def test_up_with_ports(self) -> None: |
| 19 |
up_cmd = [ |
| 20 |
"coverage", |
| 21 |
"run", |
| 22 |
podman_compose_path(), |
| 23 |
"-f", |
| 24 |
os.path.join(test_path(), "ports", "docker-compose.yml"), |
| 25 |
"up", |
| 26 |
"-d", |
| 27 |
"--force-recreate", |
| 28 |
] |
| 29 |
|
| 30 |
down_cmd = [ |
| 31 |
"coverage", |
| 32 |
"run", |
| 33 |
podman_compose_path(), |
| 34 |
"-f", |
| 35 |
os.path.join(test_path(), "ports", "docker-compose.yml"), |
| 36 |
"down", |
| 37 |
] |
| 38 |
|
| 39 |
port_cmd = [ |
| 40 |
podman_compose_path(), |
| 41 |
"-f", |
| 42 |
os.path.join(test_path(), "ports", "docker-compose.yml"), |
| 43 |
"port", |
| 44 |
] |
| 45 |
|
| 46 |
udp_arg = ["--protocol", "udp"] |
| 47 |
|
| 48 |
tcp_arg = ["--protocol", "tcp"] |
| 49 |
|
| 50 |
try: |
| 51 |
self.run_subprocess_assert_returncode(up_cmd) |
| 52 |
|
| 53 |
port = self.run_subprocess_assert_returncode(port_cmd + ["web1", "8000"]) |
| 54 |
self.assertEqual(port[0].decode().strip(), "8000") |
| 55 |
|
| 56 |
port = self.run_subprocess_assert_returncode(port_cmd + ["web1", "8001"]) |
| 57 |
self.assertNotEqual(port[0].decode().strip(), "8001") |
| 58 |
|
| 59 |
port = self.run_subprocess_assert_returncode(port_cmd + ["web2", "8002"]) |
| 60 |
self.assertEqual(port[0].decode().strip(), "8002") |
| 61 |
|
| 62 |
port = self.run_subprocess_assert_returncode(port_cmd + udp_arg + ["web2", "8003"]) |
| 63 |
self.assertEqual(port[0].decode().strip(), "8003") |
| 64 |
|
| 65 |
port = self.run_subprocess_assert_returncode(port_cmd + ["web2", "8004"]) |
| 66 |
self.assertEqual(port[0].decode().strip(), "8004") |
| 67 |
|
| 68 |
port = self.run_subprocess_assert_returncode(port_cmd + tcp_arg + ["web2", "8005"]) |
| 69 |
self.assertEqual(port[0].decode().strip(), "8005") |
| 70 |
|
| 71 |
port = self.run_subprocess_assert_returncode(port_cmd + udp_arg + ["web2", "8006"]) |
| 72 |
self.assertNotEqual(port[0].decode().strip(), "8006") |
| 73 |
|
| 74 |
port = self.run_subprocess_assert_returncode(port_cmd + ["web2", "8007"]) |
| 75 |
self.assertNotEqual(port[0].decode().strip(), "8007") |
| 76 |
|
| 77 |
finally: |
| 78 |
self.run_subprocess_assert_returncode(down_cmd) |