| 1 |
|
| 2 |
|
| 3 |
import os |
| 4 |
import unittest |
| 5 |
|
| 6 |
from tests.integration.test_utils import RunSubprocessMixin |
| 7 |
from tests.integration.test_utils import podman_compose_path |
| 8 |
from tests.integration.test_utils import test_path |
| 9 |
|
| 10 |
|
| 11 |
def compose_yaml_path(version: str = '1') -> str: |
| 12 |
return os.path.join(os.path.join(test_path(), "no_recreate"), f"compose{version}.yaml") |
| 13 |
|
| 14 |
|
| 15 |
class TestComposeNoRecreate(unittest.TestCase, RunSubprocessMixin): |
| 16 |
def test_no_recreate(self) -> None: |
| 17 |
def up(args: list[str] = [], version: str = '1') -> None: |
| 18 |
self.run_subprocess_assert_returncode( |
| 19 |
[ |
| 20 |
podman_compose_path(), |
| 21 |
"-f", |
| 22 |
compose_yaml_path(version), |
| 23 |
"up", |
| 24 |
"-t", |
| 25 |
"0", |
| 26 |
"-d", |
| 27 |
*args, |
| 28 |
], |
| 29 |
) |
| 30 |
|
| 31 |
def get_container_id() -> bytes: |
| 32 |
return self.run_subprocess_assert_returncode([ |
| 33 |
podman_compose_path(), |
| 34 |
"-f", |
| 35 |
compose_yaml_path(), |
| 36 |
"ps", |
| 37 |
"--format", |
| 38 |
'{{.ID}}', |
| 39 |
])[0] |
| 40 |
|
| 41 |
try: |
| 42 |
up() |
| 43 |
|
| 44 |
container_id = get_container_id() |
| 45 |
|
| 46 |
self.assertGreater(len(container_id), 0) |
| 47 |
|
| 48 |
|
| 49 |
up() |
| 50 |
self.assertEqual(get_container_id(), container_id) |
| 51 |
|
| 52 |
|
| 53 |
up(version='2') |
| 54 |
self.assertNotEqual(get_container_id(), container_id) |
| 55 |
|
| 56 |
container_id = get_container_id() |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
up(["--no-recreate"], version='1') |
| 61 |
self.assertEqual(get_container_id(), container_id) |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
up(["--force-recreate"], version='1') |
| 66 |
self.assertNotEqual(get_container_id(), container_id) |
| 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 |
]) |