| 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 networks_no_services_compose() -> str: |
| 12 |
return compose_yaml_path("docker-compose-networks-no-services.yaml") |
| 13 |
|
| 14 |
|
| 15 |
def empty_services_compose() -> str: |
| 16 |
return compose_yaml_path("docker-compose-empty-services.yaml") |
| 17 |
|
| 18 |
|
| 19 |
def compose_yaml_path(filename: str) -> str: |
| 20 |
return os.path.join(os.path.join(test_path(), "no_services"), filename) |
| 21 |
|
| 22 |
|
| 23 |
class TestComposeNoServices(unittest.TestCase, RunSubprocessMixin): |
| 24 |
|
| 25 |
def test_no_services(self) -> None: |
| 26 |
try: |
| 27 |
_, err = self.run_subprocess_assert_returncode( |
| 28 |
[ |
| 29 |
podman_compose_path(), |
| 30 |
"-f", |
| 31 |
networks_no_services_compose(), |
| 32 |
"up", |
| 33 |
"-d", |
| 34 |
], |
| 35 |
) |
| 36 |
self.assertIn(b'WARNING:__main__:WARNING: unused networks: shared-network\n', err) |
| 37 |
|
| 38 |
container_id, _ = self.run_subprocess_assert_returncode([ |
| 39 |
podman_compose_path(), |
| 40 |
"-f", |
| 41 |
networks_no_services_compose(), |
| 42 |
"ps", |
| 43 |
"--format", |
| 44 |
'{{.ID}}', |
| 45 |
]) |
| 46 |
self.assertEqual(container_id, b"") |
| 47 |
finally: |
| 48 |
self.run_subprocess_assert_returncode([ |
| 49 |
podman_compose_path(), |
| 50 |
"-f", |
| 51 |
networks_no_services_compose(), |
| 52 |
"down", |
| 53 |
"-t", |
| 54 |
"0", |
| 55 |
]) |
| 56 |
|
| 57 |
def test_empty_services_no_stacktrace(self) -> None: |
| 58 |
try: |
| 59 |
_, err = self.run_subprocess_assert_returncode([ |
| 60 |
podman_compose_path(), |
| 61 |
"-f", |
| 62 |
empty_services_compose(), |
| 63 |
"up", |
| 64 |
"-d", |
| 65 |
]) |
| 66 |
self.assertNotIn(b"\nTraceback (most recent call last):\n", err) |
| 67 |
finally: |
| 68 |
self.run_subprocess_assert_returncode([ |
| 69 |
podman_compose_path(), |
| 70 |
"-f", |
| 71 |
empty_services_compose(), |
| 72 |
"down", |
| 73 |
"-t", |
| 74 |
"0", |
| 75 |
]) |