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 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.
/// To check if i) non-interactive sudo is possible and ii) if sudo works, this runs:
/// 'sudo -E --non-interactive whoami' first.
@ -1264,6 +1264,7 @@ pub fn run_ucmd_as_root(
ts: &TestScenario,
args: &[&str],
) -> std::result::Result<CmdResult, String> {
// Apparently CICD environment has no `sudo`?
if ts
.cmd_keepenv("sudo")
.env("LC_ALL", "C")
@ -1580,16 +1581,18 @@ mod tests {
#[cfg(unix)]
#[cfg(feature = "whoami")]
fn test_run_ucmd_as_root() {
// We need non-interactive `sudo.
// CICD environment should allow non-interactive `sudo`.
// Return early if we can't guarantee non-interactive `sudo`
if !is_ci() {
return;
}
// Skip test if we can't guarantee non-interactive `sudo`.
if let Ok(_status) = Command::new("sudo")
.args(&["-E", "-v", "--non-interactive"])
.status()
{
let ts = TestScenario::new("whoami");
std::assert_eq!(
run_ucmd_as_root(&ts, &[]).unwrap().stdout_str().trim(),
"root"
);
} else {
print!("TEST SKIPPED");
}
}
}