Skip to content

Commit b513f50

Browse files
test: add missing unit tests for selinux in verbose mount
Support for setting the selinux flags on a bind mount specified using the verbose syntax was merged as part of #911, but at that time the PR lacked unit tests. This commit adds the missing tests Signed-off-by: charliemirabile <[email protected]>
1 parent 5d4de80 commit b513f50

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pytests/test_container_to_args.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from os import path
55
from unittest import mock
66

7+
from parameterized import parameterized
8+
79
from podman_compose import container_to_args
810

911

@@ -428,3 +430,43 @@ async def test_gpu(self):
428430
"nvidia-smi",
429431
],
430432
)
433+
434+
@parameterized.expand([
435+
(False, "z", ["--mount", "type=bind,source=./foo,destination=/mnt,z"]),
436+
(False, "Z", ["--mount", "type=bind,source=./foo,destination=/mnt,Z"]),
437+
(True, "z", ["-v", "./foo:/mnt:z"]),
438+
(True, "Z", ["-v", "./foo:/mnt:Z"]),
439+
])
440+
async def test_selinux_volume(self, prefer_volume, selinux_type, expected_additional_args):
441+
c = create_compose_mock()
442+
c.prefer_volume_over_mount = prefer_volume
443+
444+
cnt = get_minimal_container()
445+
446+
# This is supposed to happen during `_parse_compose_file`
447+
# but that is probably getting skipped during testing
448+
cnt["_service"] = cnt["service_name"]
449+
450+
cnt["volumes"] = [
451+
{
452+
"type": "bind",
453+
"source": "./foo",
454+
"target": "/mnt",
455+
"bind": {
456+
"selinux": selinux_type,
457+
},
458+
}
459+
]
460+
461+
args = await container_to_args(c, cnt)
462+
self.assertEqual(
463+
args,
464+
[
465+
"--name=project_name_service_name1",
466+
"-d",
467+
*expected_additional_args,
468+
"--network=bridge",
469+
"--network-alias=service_name",
470+
"busybox",
471+
],
472+
)

0 commit comments

Comments
 (0)