Debian Codegraph @

tests/integration/logs/test_podman_compose_logs.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2
3
4 import os
5 import unittest
6
7 from parameterized import parameterized
8
9 from tests.integration.test_utils import RunSubprocessMixin
10 from tests.integration.test_utils import podman_compose_path
11 from tests.integration.test_utils import test_path
12
13
14 class TestLogs(unittest.TestCase, RunSubprocessMixin):
15 @parameterized.expand([
16 (
17 "all_services_no_flag",
18 [],
19 [
20 b'',
21 b'\x1b[1;32m[test1] |\x1b[0m \x1b[37mtest1\x1b[0m',
22 b'\x1b[1;33m[test2] |\x1b[0m \x1b[37mtest2\x1b[0m',
23 b'\x1b[1;34m[test3] |\x1b[0m \x1b[37mtest3\x1b[0m',
24 ],
25 ),
26 (
27 "all_services_flag_no_color",
28 ["--no-color"],
29 [
30 b'',
31 b'\x1b[0m[test1] |\x1b[0m test1',
32 b'\x1b[0m[test2] |\x1b[0m test2',
33 b'\x1b[0m[test3] |\x1b[0m test3',
34 ],
35 ),
36 (
37 "all_services_flag_no_log_prefix",
38 ["--no-log-prefix"],
39 [b'', b'\x1b[37mtest1\x1b[0m', b'\x1b[37mtest2\x1b[0m', b'\x1b[37mtest3\x1b[0m'],
40 ),
41 (
42 "all_services_flag_no_color_no_log_prefix",
43 ["--no-color", "--no-log-prefix"],
44 [b'', b'test1', b'test2', b'test3'],
45 ),
46 (
47 "one_service_no_flag",
48 ["test1"],
49 [b'', b'\x1b[1;32m[test1] |\x1b[0m \x1b[37mtest1\x1b[0m'],
50 ),
51 (
52 "one_service_flag_no_color",
53 ["test1", "--no-color"],
54 [b'', b'\x1b[0m[test1] |\x1b[0m test1'],
55 ),
56 (
57 "one_service_flag_no_log_prefix",
58 ["test1", "--no-log-prefix"],
59 [b'', b'\x1b[37mtest1\x1b[0m'],
60 ),
61 (
62 "one_service_flag_no_color_no_log_prefix",
63 ["test1", "--no-color", "--no-log-prefix"],
64 [b'', b'test1'],
65 ),
66 (
67 "two_services_no_flag",
68 ["test2", "test3"],
69 [
70 b'',
71 b'\x1b[1;32m[test2] |\x1b[0m \x1b[37mtest2\x1b[0m',
72 b'\x1b[1;33m[test3] |\x1b[0m \x1b[37mtest3\x1b[0m',
73 ],
74 ),
75 (
76 "two_services_flag_no_color",
77 ["test2", "test3", "--no-color"],
78 [b'', b'\x1b[0m[test2] |\x1b[0m test2', b'\x1b[0m[test3] |\x1b[0m test3'],
79 ),
80 (
81 "two_services_flag_no_log_prefix",
82 ["test2", "test3", "--no-log-prefix"],
83 [b'', b'\x1b[37mtest2\x1b[0m', b'\x1b[37mtest3\x1b[0m'],
84 ),
85 (
86 "two_services_flag_no_color_no_log_prefix",
87 ["test2", "test3", "--no-color", "--no-log-prefix"],
88 [b'', b'test2', b'test3'],
89 ),
90 ])
91 def test_logs(
92 self, test_name: str, additional_args: list[str], expected_log: list[bytes]
93 ) -> None:
94 compose_path = os.path.join(test_path(), "logs/docker-compose.yml")
95
96 try:
97 self.run_subprocess_assert_returncode([
98 podman_compose_path(),
99 "-f",
100 compose_path,
101 "up",
102 "-d",
103 ])
104 command_args = [
105 podman_compose_path(),
106 "-f",
107 compose_path,
108 "logs",
109 ]
110 command_args.extend(additional_args)
111 out, _ = self.run_subprocess_assert_returncode(command_args)
112 lines = out.split(b'\n')
113 lines.sort()
114 self.assertEqual(lines, expected_log)
115 finally:
116 out, _ = self.run_subprocess_assert_returncode([
117 podman_compose_path(),
118 "-f",
119 compose_path,
120 "down",
121 ])