Skip to content

Commit 0adc0b4

Browse files
committed
tests/unit: Add unit tests for create_host_path implementation
Signed-off-by: Monika Kairaityte <[email protected]>
1 parent 98d9539 commit 0adc0b4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/unit/test_container_to_args.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,69 @@ async def test_volumes_bind_mount_source(
679679
],
680680
)
681681

682+
@parameterized.expand([
683+
(
684+
"create_host_path_set_to_true",
685+
{"bind": {"create_host_path": True}},
686+
),
687+
(
688+
"create_host_path_default_true",
689+
{},
690+
),
691+
])
692+
# creates a missing source dir
693+
async def test_volumes_bind_mount_create_source_dir(self, test_name: str, bind: dict) -> None:
694+
c = create_compose_mock()
695+
c.prefer_volume_over_mount = True
696+
cnt = get_minimal_container()
697+
698+
cnt["_service"] = cnt["service_name"]
699+
700+
volume_info = {
701+
"type": "bind",
702+
"source": "./not_exists/foo",
703+
"target": "/mnt",
704+
}
705+
volume_info.update(bind)
706+
cnt["volumes"] = [
707+
volume_info,
708+
]
709+
710+
args = await container_to_args(c, cnt)
711+
712+
self.assertEqual(
713+
args,
714+
[
715+
"--name=project_name_service_name1",
716+
"-d",
717+
"-v",
718+
f"{get_test_file_path('./test_dirname/not_exists/foo')}:/mnt",
719+
"--network=bridge:alias=service_name",
720+
"busybox",
721+
],
722+
)
723+
724+
# throws an error as the source path does not exist and its creation was suppressed with the
725+
# create_host_path = False option
726+
async def test_volumes_bind_mount_source_does_not_exist(self) -> None:
727+
c = create_compose_mock()
728+
c.prefer_volume_over_mount = True
729+
cnt = get_minimal_container()
730+
731+
cnt["_service"] = cnt["service_name"]
732+
733+
cnt["volumes"] = [
734+
{
735+
"type": "bind",
736+
"source": './not_exists/foo',
737+
"target": "/mnt",
738+
"bind": {"create_host_path": False},
739+
}
740+
]
741+
742+
with self.assertRaises(ValueError):
743+
await container_to_args(c, cnt)
744+
682745
@parameterized.expand([
683746
("not_compat", False, "test_project_name", "test_project_name_network1"),
684747
("compat_no_dash", True, "test_project_name", "test_project_name_network1"),

0 commit comments

Comments
 (0)