Skip to content

Commit 06f5a68

Browse files
committed
feat(test): Add test for creating dev env with extra bind mounts
1 parent 766e26a commit 06f5a68

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

tests/env/dev/types/test_linux_container.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,117 @@ def test_multiple_clones(self, dda, helpers, mocker, temp_dir, host_user_args):
615615
),
616616
]
617617

618+
@pytest.mark.parametrize(
619+
"volume_binds",
620+
[
621+
# Case 1: Single absolute path
622+
[
623+
"-v",
624+
"/tmp/mounted:/tmp/mounted_abs",
625+
],
626+
# Case 2: Single relative path
627+
[
628+
"-v",
629+
"./mounted:/tmp/mounted_rel",
630+
],
631+
# Case 3: Multiple mounts
632+
[
633+
"-v",
634+
"/tmp/mounted:/tmp/mounted_abs",
635+
"-v",
636+
"./mounted:/tmp/mounted_rel",
637+
],
638+
# Case 4: Mounts with flags
639+
[
640+
"-v",
641+
"/tmp/mounted:/tmp/mounted_abs:ro",
642+
"-v",
643+
"./mounted:/tmp/mounted_rel:rw",
644+
],
645+
],
646+
)
647+
def test_extra_bind_mounts(self, dda, helpers, mocker, temp_dir, host_user_args, volume_binds):
648+
write_server_config = mocker.patch("dda.utils.ssh.write_server_config")
649+
shared_dir = temp_dir / "data" / "env" / "dev" / "linux-container" / ".shared"
650+
starship_mount = get_starship_mount(shared_dir)
651+
cache_volumes = get_cache_volumes()
652+
with (
653+
temp_dir.as_cwd(),
654+
helpers.hybrid_patch(
655+
"subprocess.run",
656+
return_values={
657+
# Start command checks the status
658+
1: CompletedProcess([], returncode=0, stdout="{}"),
659+
# Start method checks the status
660+
2: CompletedProcess([], returncode=0, stdout="{}"),
661+
# Capture container run
662+
# Readiness check
663+
4: CompletedProcess([], returncode=0, stdout="Server listening on :: port 22"),
664+
# Repo cloning
665+
5: CompletedProcess([], returncode=0, stdout="{}"),
666+
},
667+
) as calls,
668+
):
669+
result = dda(
670+
"env",
671+
"dev",
672+
"start",
673+
"--no-pull",
674+
"--clone",
675+
*volume_binds,
676+
)
677+
678+
result.check(
679+
exit_code=0,
680+
stdout=helpers.dedent(
681+
"""
682+
Creating and starting container: dda-linux-container-default
683+
Waiting for container: dda-linux-container-default
684+
Cloning repository: datadog-agent
685+
"""
686+
),
687+
)
688+
689+
assert calls == [
690+
(
691+
(
692+
[
693+
helpers.locate("docker"),
694+
"run",
695+
"--pull",
696+
"never",
697+
"-d",
698+
"--name",
699+
"dda-linux-container-default",
700+
"-p",
701+
"61938:22",
702+
"-p",
703+
"50069:9000",
704+
"-v",
705+
"/var/run/docker.sock:/var/run/docker.sock",
706+
*host_user_args,
707+
"-e",
708+
"DD_SHELL",
709+
"-e",
710+
AppEnvVars.TELEMETRY_API_KEY,
711+
"-e",
712+
AppEnvVars.TELEMETRY_USER_MACHINE_ID,
713+
"-e",
714+
GitEnvVars.AUTHOR_NAME,
715+
"-e",
716+
GitEnvVars.AUTHOR_EMAIL,
717+
*starship_mount,
718+
"-v",
719+
f"{shared_dir / 'shell' / 'zsh' / '.zsh_history'}:/root/.shared/shell/zsh/.zsh_history",
720+
*cache_volumes,
721+
*volume_binds,
722+
"datadog/agent-dev-env-linux",
723+
],
724+
),
725+
{"encoding": "utf-8", "stdout": subprocess.PIPE, "stderr": subprocess.PIPE, "env": mocker.ANY},
726+
),
727+
]
728+
618729

619730
class TestStop:
620731
def test_nonexistent(self, dda, helpers, mocker):

0 commit comments

Comments
 (0)