| 1 |
|
| 2 |
|
| 3 |
import os |
| 4 |
import unittest |
| 5 |
|
| 6 |
import requests |
| 7 |
|
| 8 |
from tests.integration.test_utils import RunSubprocessMixin |
| 9 |
from tests.integration.test_utils import podman_compose_path |
| 10 |
from tests.integration.test_utils import test_path |
| 11 |
|
| 12 |
|
| 13 |
def compose_yaml_path() -> str: |
| 14 |
return os.path.join(os.path.join(test_path(), "nethost"), "docker-compose.yaml") |
| 15 |
|
| 16 |
|
| 17 |
class TestComposeNethost(unittest.TestCase, RunSubprocessMixin): |
| 18 |
|
| 19 |
|
| 20 |
def test_nethost(self) -> None: |
| 21 |
try: |
| 22 |
self.run_subprocess_assert_returncode( |
| 23 |
[podman_compose_path(), "-f", compose_yaml_path(), "up", "-d"], |
| 24 |
) |
| 25 |
|
| 26 |
container_id_out, _ = self.run_subprocess_assert_returncode( |
| 27 |
[ |
| 28 |
podman_compose_path(), |
| 29 |
"-f", |
| 30 |
compose_yaml_path(), |
| 31 |
"ps", |
| 32 |
"--format", |
| 33 |
'{{.ID}}', |
| 34 |
], |
| 35 |
) |
| 36 |
container_id = container_id_out.decode('utf-8').split('\n')[0] |
| 37 |
output, _ = self.run_subprocess_assert_returncode( |
| 38 |
[ |
| 39 |
"podman", |
| 40 |
"exec", |
| 41 |
"-it", |
| 42 |
container_id, |
| 43 |
"sh", |
| 44 |
"-c", |
| 45 |
"echo test_123 >> /tmp/test.txt", |
| 46 |
], |
| 47 |
) |
| 48 |
response = requests.get('http://localhost:8123/test.txt') |
| 49 |
self.assertEqual(response.ok, True) |
| 50 |
self.assertEqual(response.text, "test_123\n") |
| 51 |
finally: |
| 52 |
self.run_subprocess_assert_returncode([ |
| 53 |
podman_compose_path(), |
| 54 |
"-f", |
| 55 |
compose_yaml_path(), |
| 56 |
"down", |
| 57 |
"-t", |
| 58 |
"0", |
| 59 |
]) |