Debian Codegraph @

tests/integration/multicompose/test_podman_compose_multicompose.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
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(), "multicompose"), "docker-compose.yml")
13
14
15 class TestComposeMulticompose(unittest.TestCase, RunSubprocessMixin):
16 def test_multicompose(self) -> None:
17 try:
18 self.run_subprocess_assert_returncode(
19 [
20 podman_compose_path(),
21 "-f",
22 os.path.join(
23 os.path.join(test_path(), "multicompose"), "d1/docker-compose.yml"
24 ),
25 "-f",
26 os.path.join(
27 os.path.join(test_path(), "multicompose"), "d2/docker-compose.yml"
28 ),
29 "up",
30 "-d",
31 ],
32 )
33 output, _ = self.run_subprocess_assert_returncode([
34 podman_compose_path(),
35 "-f",
36 os.path.join(os.path.join(test_path(), "multicompose"), "d1/docker-compose.yml"),
37 "-f",
38 os.path.join(os.path.join(test_path(), "multicompose"), "d2/docker-compose.yml"),
39 "ps",
40 ])
41 self.assertIn(b"d1_web1_1", output)
42 self.assertIn(b"d1_web2_1", output)
43
44 output, _ = self.run_subprocess_assert_returncode([
45 "podman",
46 "exec",
47 "-ti",
48 "d1_web1_1",
49 "sh",
50 "-c",
51 "set",
52 ])
53 # checks if `env_file` was appended, not replaced
54 # (which means that we normalize to array before merge)
55 self.assertIn(b"var12='d1/12.env'", output)
56
57 output, _ = self.run_subprocess_assert_returncode([
58 "podman",
59 "exec",
60 "-ti",
61 "d1_web2_1",
62 "sh",
63 "-c",
64 "set",
65 ])
66 # checks if paths inside `d2/docker-compose.yml` directory are relative to `d1`
67 self.assertIn(b"var2='d1/2.env'", output)
68
69 output, _ = self.run_subprocess_assert_returncode([
70 "podman",
71 "exec",
72 "-ti",
73 "d1_web1_1",
74 "sh",
75 "-c",
76 "cat /var/www/html/index.txt",
77 ])
78 self.assertIn(b"var1=d1/1.env", output)
79
80 # check if project base directory and project name is d1
81 output, _ = self.run_subprocess_assert_returncode([
82 "podman",
83 "exec",
84 "-ti",
85 "d1_web2_1",
86 "sh",
87 "-c",
88 "cat /var/www/html/index.txt",
89 ])
90 self.assertIn(b"var2=d1/2.env", output)
91 finally:
92 self.run_subprocess_assert_returncode([
93 podman_compose_path(),
94 "-f",
95 os.path.join(os.path.join(test_path(), "multicompose"), "d1/docker-compose.yml"),
96 "-f",
97 os.path.join(os.path.join(test_path(), "multicompose"), "d2/docker-compose.yml"),
98 "down",
99 "-t",
100 "0",
101 ])