Skip to content

Commit

Permalink
test: add missing unit tests for selinux in verbose mount
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
charliemirabile committed May 21, 2024
1 parent 5d4de80 commit baea8c3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pytests/test_container_to_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from os import path
from unittest import mock

from parameterized import parameterized

from podman_compose import container_to_args


Expand Down Expand Up @@ -428,3 +430,44 @@ async def test_gpu(self):
"nvidia-smi",
],
)

@parameterized.expand([
(False, "z", ["--mount", "type=bind,source=./foo,destination=/mnt,z"]),
(False, "Z", ["--mount", "type=bind,source=./foo,destination=/mnt,Z"]),
(True, "z", ["-v", "./foo:/mnt:z"]),
(True, "Z", ["-v", "./foo:/mnt:Z"]),
])
async def test_selinux_volume(self, prefer_volume, selinux_type, expected_additional_args):
c = create_compose_mock()
c.prefer_volume_over_mount = prefer_volume

cnt = get_minimal_container()

# This is supposed to happen during `_parse_compose_file`
# but that is probably getting skipped during testing
cnt["_service"] = cnt["service_name"]

cnt["volumes"] = [
{
"type": "bind",
"source": "./foo",
"target": "/mnt",
"bind": {
"selinux": selinux_type,
},
}
]

args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
*expected_additional_args,
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)

0 comments on commit baea8c3

Please sign in to comment.