Debian Codegraph @

tests/integration/vol/long_syntax/test_podman_compose_vol_long_syntax.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2
3 import os
4 import shutil
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 def compose_yaml_path(test_ref_folder: str) -> str:
15 return os.path.join(test_path(), "vol", test_ref_folder, "docker-compose.yml")
16
17
18 class TestComposeVolLongSyntax(unittest.TestCase, RunSubprocessMixin):
19 @parameterized.expand([
20 (True, "create_host_path_default_true"),
21 (True, "create_host_path_true"),
22 (True, "create_host_path_false"),
23 (False, "create_host_path_default_true"),
24 (False, "create_host_path_true"),
25 ])
26 def test_source_host_dir(self, source_dir_exists: bool, service_name: str) -> None:
27 project_dir = os.path.join(test_path(), "vol", "long_syntax")
28 if source_dir_exists:
29 # create host source directory for volume
30 os.mkdir(os.path.join(project_dir, "test_dir"))
31 else:
32 # make sure there is no such directory
33 self.assertFalse(os.path.isdir(os.path.join(project_dir, "test_dir")))
34
35 try:
36 self.run_subprocess_assert_returncode(
37 [
38 podman_compose_path(),
39 "-f",
40 compose_yaml_path("long_syntax"),
41 "up",
42 "-d",
43 f"{service_name}",
44 ],
45 0,
46 )
47 # command of the service creates a new directory on mounted directory 'test_dir' in
48 # the container. Check if host directory now has the same directory. It represents a
49 # successful mount.
50 # If source host directory does not exist, it is created
51 self.assertTrue(os.path.isdir(os.path.join(project_dir, "test_dir/new_dir")))
52
53 finally:
54 self.run_subprocess_assert_returncode([
55 podman_compose_path(),
56 "-f",
57 compose_yaml_path("long_syntax"),
58 "down",
59 "-t",
60 "0",
61 ])
62 shutil.rmtree(os.path.join(project_dir, "test_dir"))
63
64 def test_no_host_source_dir_create_host_path_false(self) -> None:
65 try:
66 _, error = self.run_subprocess_assert_returncode(
67 [
68 podman_compose_path(),
69 "-f",
70 compose_yaml_path("long_syntax"),
71 "up",
72 "-d",
73 "create_host_path_false",
74 ],
75 1,
76 )
77 self.assertIn(
78 b"invalid mount config for type 'bind': bind source path does not exist:", error
79 )
80 finally:
81 self.run_subprocess([
82 podman_compose_path(),
83 "-f",
84 compose_yaml_path("long_syntax"),
85 "down",
86 "-t",
87 "0",
88 ])