Skip to content

Commit

Permalink
chroot: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Sep 20, 2022
1 parent 6051c46 commit 58cfc7f
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions tests/by-util/test_chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,34 @@ fn test_default_shell() {
at.mkdir(dir);

let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
let _expected = format!(
let expected = format!(
"chroot: failed to run command '{}': No such file or directory",
shell
);

// TODO: [2021-09; jhscheer] uncomment if/when #2692 gets merged
// if let Ok(result) = run_ucmd_as_root(&ts, &[dir]) {
// result.stderr_contains(expected);
// } else {
// print!("TEST SKIPPED");
// }
if let Ok(result) = run_ucmd_as_root(&ts, &[dir]) {
result.stderr_contains(expected);
} else {
print!("TEST SKIPPED");
}
}

#[test]
fn test_chroot() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;

let dir = "CHROOT_DIR";
at.mkdir(dir);
if let Ok(result) = run_ucmd_as_root(&ts, &[dir, "whoami"]) {
result.success().no_stderr().stdout_is("root");
} else {
print!("Test skipped; requires root user");
}

if let Ok(result) = run_ucmd_as_root(&ts, &[dir, "pwd"]) {
result.success().no_stderr().stdout_is("/");
} else {
print!("Test skipped; requires root user");
}
}

0 comments on commit 58cfc7f

Please sign in to comment.