MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / run_without_docker

Function run_without_docker

e2e/rust/tests/docker_preflight.rs:28–66  ·  view source on GitHub ↗

Run `openshell ` in an isolated environment where Docker is guaranteed to be unreachable. Sets `DOCKER_HOST` to a non-existent socket so the preflight check fails immediately regardless of the host's Docker configuration.

(args: &[&str])

Source from the content-addressed store, hash-verified

26/// Sets `DOCKER_HOST` to a non-existent socket so the preflight check
27/// fails immediately regardless of the host's Docker configuration.
28async fn run_without_docker(args: &[&str]) -> (String, i32, std::time::Duration) {
29 let tmpdir = tempfile::tempdir().expect("create isolated config dir");
30 let bin_dir = tmpdir.path().join("bin");
31 fs::create_dir(&bin_dir).expect("create fake bin dir");
32 let fake_docker = bin_dir.join("docker");
33 fs::write(
34 &fake_docker,
35 "#!/bin/sh\n\
36 echo 'Cannot connect to Docker daemon. Check DOCKER_HOST and run docker info.' >&2\n\
37 exit 1\n",
38 )
39 .expect("write fake docker");
40 #[cfg(unix)]
41 fs::set_permissions(&fake_docker, fs::Permissions::from_mode(0o755))
42 .expect("chmod fake docker");
43
44 let old_path = env::var("PATH").unwrap_or_default();
45 let path = format!("{}:{old_path}", bin_dir.display());
46 let start = Instant::now();
47
48 let mut cmd = openshell_cmd();
49 cmd.args(args)
50 .env("XDG_CONFIG_HOME", tmpdir.path())
51 .env("HOME", tmpdir.path())
52 .env("PATH", path)
53 .env("DOCKER_HOST", "unix:///tmp/openshell-e2e-nonexistent.sock")
54 .env_remove("OPENSHELL_GATEWAY")
55 .env_remove("OPENSHELL_GATEWAY_ENDPOINT")
56 .stdout(Stdio::piped())
57 .stderr(Stdio::piped());
58
59 let output = cmd.output().await.expect("spawn openshell");
60 let elapsed = start.elapsed();
61 let stdout = String::from_utf8_lossy(&output.stdout).to_string();
62 let stderr = String::from_utf8_lossy(&output.stderr).to_string();
63 let combined = format!("{stdout}{stderr}");
64 let code = output.status.code().unwrap_or(-1);
65 (combined, code, elapsed)
66}
67
68// -------------------------------------------------------------------
69// doctor check: validates system prerequisites

Calls 3

openshell_cmdFunction · 0.85
pathMethod · 0.80
codeMethod · 0.80

Tested by

no test coverage detected