1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

Add example unittest for container lib (#505)

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
Sergey 2022-10-31 18:39:46 -04:00 committed by GitHub
parent c952149603
commit 05dc08c201
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,89 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
from ansible_collections.containers.podman.plugins.module_utils.podman.podman_container_lib import (
PodmanModuleParams,
PodmanContainerDiff,
)
@pytest.mark.parametrize(
"test_input, expected",
[
(
{
"cap_add": ["SYS_ADMIN"],
"name": "testcont",
"image": "testimage",
"command": None,
},
[
b"create",
b"--name",
b"testcont",
b"--cap-add",
b"SYS_ADMIN",
b"testimage",
],
),
(
{
"stop_signal": 9,
"name": "testcont",
"image": "testimage",
"command": None,
"sig_proxy": True,
},
[
b"create",
b"--name",
b"testcont",
b"--stop-signal",
b"9",
b"--sig-proxy=True",
b"testimage",
],
),
],
)
def test_container_add_params(test_input, expected):
podm = PodmanModuleParams(
"create",
test_input,
"4.0.0",
None,
)
assert podm.construct_command_from_params() == expected
@pytest.mark.parametrize(
"test_input, expected",
[
(
[
None, # module
{"conmon_pidfile": "bbb"}, # module params
{"conmonpidfile": "ccc"}, # container info
{}, # image info
"4.1.1", # podman version
],
True,
),
(
[
None, # module
{"conmon_pidfile": None}, # module params
{"conmonpidfile": "ccc"}, # container info
{}, # image info
"4.1.1", # podman version
],
False,
),
],
)
def test_container_diff(test_input, expected):
diff = PodmanContainerDiff(*test_input)
assert diff.diffparam_conmon_pidfile() == expected