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:
parent
c952149603
commit
05dc08c201
1 changed files with 89 additions and 0 deletions
89
tests/unit/plugins/modules/test_container_lib.py
Normal file
89
tests/unit/plugins/modules/test_container_lib.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue