Debian Codegraph @

ansible_collections/containers/podman/tests/unit/plugins/modules/test_container_lib.py

raw
1 from __future__ import absolute_import, division, print_function
2
3 __metaclass__ = type
4
5 import pytest
6
7 from ansible_collections.containers.podman.plugins.module_utils.podman.podman_container_lib import (
8 PodmanContainerDiff,
9 PodmanModuleParams,
10 )
11
12
13 @pytest.mark.parametrize(
14 "test_input, expected",
15 [
16 (
17 {
18 "cap_add": ["SYS_ADMIN"],
19 "name": "testcont",
20 "image": "testimage",
21 "command": None,
22 },
23 [
24 b"create",
25 b"--name",
26 b"testcont",
27 b"--cap-add",
28 b"SYS_ADMIN",
29 b"testimage",
30 ],
31 ),
32 (
33 {
34 "stop_signal": 9,
35 "name": "testcont",
36 "image": "testimage",
37 "command": None,
38 "sig_proxy": True,
39 },
40 [
41 b"create",
42 b"--name",
43 b"testcont",
44 b"--stop-signal",
45 b"9",
46 b"--sig-proxy=True",
47 b"testimage",
48 ],
49 ),
50 ],
51 )
52 def test_container_add_params(test_input, expected):
53 podm = PodmanModuleParams(
54 "create",
55 test_input,
56 "4.0.0",
57 None,
58 )
59 assert podm.construct_command_from_params() == expected
60
61
62 @pytest.mark.parametrize(
63 "test_input, expected",
64 [
65 (
66 [
67 None, # module
68 {"conmon_pidfile": "bbb"}, # module params
69 {
70 "conmonpidfile": "ccc",
71 "config": {
72 "createcommand": [
73 "podman",
74 "create",
75 "--conmon-pidfile=ccc",
76 "testcont",
77 ]
78 },
79 }, # container info
80 {}, # image info
81 "4.1.1", # podman version
82 ],
83 True,
84 ),
85 (
86 [
87 None, # module
88 {"conmon_pidfile": None}, # module params
89 {
90 "conmonpidfile": "ccc",
91 "config": {
92 "createcommand": [
93 "podman",
94 "create",
95 "--conmon-pidfile=ccc",
96 "testcont",
97 ]
98 },
99 }, # container info
100 {}, # image info
101 "4.1.1", # podman version
102 ],
103 True,
104 ),
105 (
106 [
107 None, # module
108 {"conmon_pidfile": None}, # module params
109 {
110 "conmonpidfile": None,
111 "config": {
112 "createcommand": [
113 "podman",
114 "create",
115 "testcont",
116 ]
117 },
118 }, # container info
119 {}, # image info
120 "4.1.1", # podman version
121 ],
122 False,
123 ),
124 (
125 [
126 None, # module
127 {"conmon_pidfile": "aaa"}, # module params
128 {
129 "conmonpidfile": None,
130 "config": {
131 "createcommand": [
132 "podman",
133 "create",
134 "testcont",
135 ]
136 },
137 }, # container info
138 {}, # image info
139 "4.1.1", # podman version
140 ],
141 True,
142 ),
143 (
144 [
145 None, # module
146 {"conmon_pidfile": "aaa"}, # module params
147 {
148 "conmonpidfile": "aaa",
149 "config": {
150 "createcommand": [
151 "podman",
152 "create",
153 "--conmon-pidfile=aaa",
154 "testcont",
155 ]
156 },
157 }, # container info
158 {}, # image info
159 "4.1.1", # podman version
160 ],
161 False,
162 ),
163 ],
164 )
165 def test_container_diff(test_input, expected):
166 diff = PodmanContainerDiff(*test_input)
167 assert diff.diffparam_conmon_pidfile() == expected