Skip to content

Commit ee52293

Browse files
fccagoup12tic
authored andcommitted
unittest: add volume mount_type test
podman_compose.py needs to be modified to allow the tests to run. In the assert_volume function, an exception was raised because compose.podman.output returns None, and the code then tries to call decode("utf-8") on it. This change removes the unnecessary call to decode. Signed-off-by: fccagou <me@fccagou.fr>
1 parent 35ab672 commit ee52293

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

podman_compose.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ async def assert_volume(compose: PodmanCompose, mount_dict: dict[str, Any]) -> N
428428
# podman volume list --format '{{.Name}}\t{{.MountPoint}}' \
429429
# -f 'label=io.podman.compose.project=HERE'
430430
try:
431-
_ = (await compose.podman.output([], "volume", ["inspect", vol_name])).decode("utf-8")
431+
await compose.podman.output([], "volume", ["inspect", vol_name])
432+
432433
except subprocess.CalledProcessError as e:
433434
if is_ext:
434435
raise RuntimeError(f"External volume [{vol_name}] does not exist") from e
@@ -450,7 +451,7 @@ async def assert_volume(compose: PodmanCompose, mount_dict: dict[str, Any]) -> N
450451
args.extend(["--opt", f"{opt}={value}"])
451452
args.append(vol_name)
452453
await compose.podman.output([], "volume", args)
453-
_ = (await compose.podman.output([], "volume", ["inspect", vol_name])).decode("utf-8")
454+
await compose.podman.output([], "volume", ["inspect", vol_name])
454455

455456

456457
def mount_desc_to_mount_args(mount_desc: dict[str, Any]) -> str:

tests/unit/test_container_to_args.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,49 @@ async def test_volumes_image_mount(
756756
],
757757
)
758758

759+
@parameterized.expand([
760+
(
761+
"without_subpath",
762+
{},
763+
"type=volume,source=volname,destination=/mnt/example",
764+
),
765+
(
766+
"with_subpath",
767+
{"volume": {"subpath": "path/to/image/folder"}},
768+
"type=volume,source=volname,destination=/mnt/example,subpath=path/to/image/folder",
769+
),
770+
])
771+
async def test_volumes_mount(
772+
self, test_name: str, volume_opts: dict, expected_mount_arg: str
773+
) -> None:
774+
c = create_compose_mock()
775+
c.vols = {"volname": {"name": "volname"}}
776+
777+
cnt = get_minimal_container()
778+
cnt["_service"] = cnt["service_name"]
779+
780+
cnt["volumes"] = [
781+
{
782+
"type": "volume",
783+
"source": "volname",
784+
"target": "/mnt/example",
785+
**volume_opts,
786+
},
787+
]
788+
789+
args = await container_to_args(c, cnt)
790+
self.assertEqual(
791+
args,
792+
[
793+
"--name=project_name_service_name1",
794+
"-d",
795+
"--mount",
796+
expected_mount_arg,
797+
"--network=bridge:alias=service_name",
798+
"busybox",
799+
],
800+
)
801+
759802
@parameterized.expand([
760803
(
761804
"create_host_path_set_to_true",

0 commit comments

Comments
 (0)