1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

Update util.rs

This commit is contained in:
Jan Scheer 2021-09-21 00:23:23 +02:00
parent 044b3eb8b7
commit 1ccf55a3dc
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828

View file

@ -1239,7 +1239,7 @@ pub fn expected_result(ts: &TestScenario, args: &[&str]) -> std::result::Result<
/// This is a convenience wrapper to run a ucmd with root permissions. /// This is a convenience wrapper to run a ucmd with root permissions.
/// This runs 'sudo -E --non-interactive target/debug/coreutils util_name args` /// This runs 'sudo -E --non-interactive target/debug/coreutils util_name args`
/// This is primarily designed to run in the CICD environment where whoami is in $path /// This is primarily designed to run in an environment where whoami is in $path
/// and where non-interactive sudo is possible. /// and where non-interactive sudo is possible.
/// To check if i) non-interactive sudo is possible and ii) if sudo works, this runs: /// To check if i) non-interactive sudo is possible and ii) if sudo works, this runs:
/// 'sudo -E --non-interactive whoami' first. /// 'sudo -E --non-interactive whoami' first.
@ -1264,6 +1264,7 @@ pub fn run_ucmd_as_root(
ts: &TestScenario, ts: &TestScenario,
args: &[&str], args: &[&str],
) -> std::result::Result<CmdResult, String> { ) -> std::result::Result<CmdResult, String> {
// Apparently CICD environment has no `sudo`?
if ts if ts
.cmd_keepenv("sudo") .cmd_keepenv("sudo")
.env("LC_ALL", "C") .env("LC_ALL", "C")
@ -1580,16 +1581,18 @@ mod tests {
#[cfg(unix)] #[cfg(unix)]
#[cfg(feature = "whoami")] #[cfg(feature = "whoami")]
fn test_run_ucmd_as_root() { fn test_run_ucmd_as_root() {
// We need non-interactive `sudo. // Skip test if we can't guarantee non-interactive `sudo`.
// CICD environment should allow non-interactive `sudo`. if let Ok(_status) = Command::new("sudo")
// Return early if we can't guarantee non-interactive `sudo` .args(&["-E", "-v", "--non-interactive"])
if !is_ci() { .status()
return; {
let ts = TestScenario::new("whoami");
std::assert_eq!(
run_ucmd_as_root(&ts, &[]).unwrap().stdout_str().trim(),
"root"
);
} else {
print!("TEST SKIPPED");
} }
let ts = TestScenario::new("whoami");
std::assert_eq!(
run_ucmd_as_root(&ts, &[]).unwrap().stdout_str().trim(),
"root"
);
} }
} }