| 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() -> str: |
| 12 |
return os.path.join(os.path.join(test_path(), "extends"), "docker-compose.yaml") |
| 13 |
|
| 14 |
|
| 15 |
class TestComposeExteds(unittest.TestCase, RunSubprocessMixin): |
| 16 |
def test_extends_service_launch_echo(self) -> None: |
| 17 |
try: |
| 18 |
self.run_subprocess_assert_returncode([ |
| 19 |
podman_compose_path(), |
| 20 |
"-f", |
| 21 |
compose_yaml_path(), |
| 22 |
"up", |
| 23 |
"echo", |
| 24 |
]) |
| 25 |
output, _ = self.run_subprocess_assert_returncode([ |
| 26 |
podman_compose_path(), |
| 27 |
"-f", |
| 28 |
compose_yaml_path(), |
| 29 |
"logs", |
| 30 |
"--no-log-prefix", |
| 31 |
"--no-color", |
| 32 |
"echo", |
| 33 |
]) |
| 34 |
self.assertEqual(output, b"Zero\n") |
| 35 |
finally: |
| 36 |
self.run_subprocess_assert_returncode([ |
| 37 |
podman_compose_path(), |
| 38 |
"-f", |
| 39 |
compose_yaml_path(), |
| 40 |
"down", |
| 41 |
]) |
| 42 |
|
| 43 |
def test_extends_service_launch_echo1(self) -> None: |
| 44 |
try: |
| 45 |
self.run_subprocess_assert_returncode([ |
| 46 |
podman_compose_path(), |
| 47 |
"-f", |
| 48 |
compose_yaml_path(), |
| 49 |
"up", |
| 50 |
"echo1", |
| 51 |
]) |
| 52 |
output, _ = self.run_subprocess_assert_returncode([ |
| 53 |
podman_compose_path(), |
| 54 |
"-f", |
| 55 |
compose_yaml_path(), |
| 56 |
"logs", |
| 57 |
"--no-log-prefix", |
| 58 |
"--no-color", |
| 59 |
"echo1", |
| 60 |
]) |
| 61 |
self.assertEqual(output, b"One\n") |
| 62 |
finally: |
| 63 |
self.run_subprocess_assert_returncode([ |
| 64 |
podman_compose_path(), |
| 65 |
"-f", |
| 66 |
compose_yaml_path(), |
| 67 |
"down", |
| 68 |
]) |
| 69 |
|
| 70 |
def test_extends_service_launch_env1(self) -> None: |
| 71 |
try: |
| 72 |
self.run_subprocess_assert_returncode([ |
| 73 |
podman_compose_path(), |
| 74 |
"-f", |
| 75 |
compose_yaml_path(), |
| 76 |
"up", |
| 77 |
"env1", |
| 78 |
]) |
| 79 |
output, _ = self.run_subprocess_assert_returncode([ |
| 80 |
podman_compose_path(), |
| 81 |
"-f", |
| 82 |
compose_yaml_path(), |
| 83 |
"logs", |
| 84 |
"--no-log-prefix", |
| 85 |
"--no-color", |
| 86 |
"env1", |
| 87 |
]) |
| 88 |
lines = output.decode('utf-8').split('\n') |
| 89 |
|
| 90 |
lines = sorted([ |
| 91 |
line |
| 92 |
for line in lines |
| 93 |
if line.startswith("BAR") |
| 94 |
or line.startswith("BAZ") |
| 95 |
or line.startswith("FOO") |
| 96 |
or line.startswith("HOME") |
| 97 |
or line.startswith("PATH") |
| 98 |
or line.startswith("container") |
| 99 |
]) |
| 100 |
self.assertEqual( |
| 101 |
lines, |
| 102 |
[ |
| 103 |
'BAR=local', |
| 104 |
'BAZ=local', |
| 105 |
'FOO=original', |
| 106 |
'HOME=/root', |
| 107 |
'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', |
| 108 |
'container=podman', |
| 109 |
], |
| 110 |
) |
| 111 |
finally: |
| 112 |
self.run_subprocess_assert_returncode([ |
| 113 |
podman_compose_path(), |
| 114 |
"-f", |
| 115 |
compose_yaml_path(), |
| 116 |
"down", |
| 117 |
]) |