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:
parent
044b3eb8b7
commit
1ccf55a3dc
1 changed files with 14 additions and 11 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue