Skip to content

Commit

Permalink
Merge pull request #92 from ipuustin/normalize-test-name
Browse files Browse the repository at this point in the history
testutil: normalize test names.
  • Loading branch information
cpuguy83 committed Apr 22, 2023
2 parents 0288f5f + 0dcb534 commit 0582758
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/containerd-shim-wasm/src/sandbox/testutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@
use super::{Error, Result};
use std::process::{Command, Stdio};

fn normalize_test_name(test: &str) -> Result<&str> {
let closure_removed = test.trim_end_matches("::{{closure}}");

// More tests and validation here if needed.

Ok(closure_removed)
}

/// Re-execs the current process with sudo and runs the given test.
/// Unless this is run in a CI environment, this may prompt the user for a password.
/// This is significantly faster than expecting the user to run the tests with sudo due to build and crate caching.
pub fn run_test_with_sudo(test: &str) -> Result<()> {
// This uses piped stdout/stderr.
// This makes it so cargo doesn't mess up the caller's TTY.

let normalized_test = normalize_test_name(test)?;

let mut cmd = Command::new("sudo")
.arg("-E")
.arg(std::fs::read_link("/proc/self/exe")?)
.arg("--")
.arg(test)
.arg(normalized_test)
.arg("--exact")
.stdin(Stdio::inherit())
.stdout(Stdio::piped())
Expand Down

0 comments on commit 0582758

Please sign in to comment.