Skip to content

Commit b9c4f2c

Browse files
committed
test(podman): make preflight diagnostics portable
Signed-off-by: Evan Lezar <[email protected]>
1 parent d44269b commit b9c4f2c

1 file changed

Lines changed: 8 additions & 35 deletions

File tree

‎crates/openshell-driver-podman/tests/podman_preflight.rs‎

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,22 @@
1717
use std::path::PathBuf;
1818
use std::time::{Duration, Instant};
1919

20-
/// Strip ANSI escape codes (e.g. colors) from a string, for readable failure
21-
/// messages. Not required for the assertions below to pass — the driver's
22-
/// own tracing output carries ANSI codes even when captured non-interactively,
23-
/// but they never fragment the substrings these tests check for — this is
24-
/// purely so a failed assertion's `{clean}` output is readable.
25-
fn strip_ansi(s: &str) -> String {
26-
let mut out = String::with_capacity(s.len());
27-
let mut chars = s.chars().peekable();
28-
29-
while let Some(c) = chars.next() {
30-
if c == '\x1b' {
31-
if chars.peek() == Some(&'[') {
32-
chars.next();
33-
for c in chars.by_ref() {
34-
if c.is_ascii_alphabetic() {
35-
break;
36-
}
37-
}
38-
}
39-
} else {
40-
out.push(c);
41-
}
42-
}
43-
44-
out
45-
}
46-
4720
/// Run `openshell-driver-podman` pointed at a Podman socket that does not
4821
/// exist, and wait for it to exit.
4922
///
5023
/// The driver retries a handful of times before giving up (to tolerate the
5124
/// socket briefly re-activating), so this can take several seconds.
5225
async fn run_with_unreachable_podman_socket() -> (String, i32, Duration, PathBuf) {
5326
let tmpdir = tempfile::tempdir().expect("create isolated socket dir");
54-
let missing_socket = tmpdir
55-
.path()
56-
.join("openshell-driver-podman-nonexistent.sock");
27+
// Use a short relative path so miette cannot insert a line-wrap gutter
28+
// inside it on platforms with long temporary-directory paths.
29+
let missing_socket = PathBuf::from("missing-podman.sock");
5730

5831
let start = Instant::now();
5932
let mut cmd = tokio::process::Command::new(env!("CARGO_BIN_EXE_openshell-driver-podman"));
6033
cmd.arg("--podman-socket")
6134
.arg(&missing_socket)
35+
.current_dir(tmpdir.path())
6236
.kill_on_drop(true)
6337
.stdout(std::process::Stdio::piped())
6438
.stderr(std::process::Stdio::piped());
@@ -102,15 +76,14 @@ async fn driver_error_names_unreachable_socket() {
10276
let (output, code, _, missing_socket) = run_with_unreachable_podman_socket().await;
10377

10478
assert_ne!(code, 0);
105-
let clean = strip_ansi(&output);
10679

10780
assert!(
108-
clean.contains("connection error"),
109-
"driver error should describe a connection failure:\n{clean}"
81+
output.contains("connection error"),
82+
"driver error should describe a connection failure:\n{output}"
11083
);
11184
assert!(
112-
clean.contains(missing_socket.to_str().expect("socket path is utf-8")),
113-
"driver error should name the unreachable socket path {}:\n{clean}",
85+
output.contains(missing_socket.to_str().expect("socket path is utf-8")),
86+
"driver error should name the unreachable socket path {}:\n{output}",
11487
missing_socket.display()
11588
);
11689
}

0 commit comments

Comments
 (0)