use log::{LevelFilter, debug};
use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};
fn init_logger() {
if TermLogger::init(
LevelFilter::Debug,
Config::default(),
TerminalMode::Stderr,
ColorChoice::Auto,
)
.is_err()
{
debug!("Not initializing another logger, as one is initialized already.");
}
}
mod fakeroot {
use rootless_run::{FakerootBackend, FakerootOptions, RootlessBackend};
use testresult::TestResult;
use super::*;
#[test]
#[cfg(target_os = "linux")]
fn fakerootbackend_run() -> TestResult {
init_logger();
let backend = FakerootBackend::new(FakerootOptions::default());
let output = backend.run(&["whoami"])?;
if !output.status.success() {
return Err(format!(
"The \"fakeroot\" call exited with a non-zero return code:\n{}",
String::from_utf8_lossy(&output.stderr)
)
.into());
}
assert_eq!("root\n", String::from_utf8_lossy(&output.stdout));
Ok(())
}
}
mod utils {
use rootless_run::{detect_virt, get_command};
use testresult::TestResult;
#[test]
#[cfg(target_os = "linux")]
fn get_command_succeeds() -> TestResult {
let command = "whoami";
if let Err(error) = get_command(command) {
panic!("Should have found command \"{command}\", but got error instead:\n{error}")
};
Ok(())
}
#[test]
#[cfg(target_os = "linux")]
fn get_command_fails() -> TestResult {
let command = "d202d7951df2c4b711ca44b4bcc9d7b363fa4252127e058c1a910ec05b6cd038d71cc21221c031c0359f993e746b07f5965cf8c5c3746a58337ad9ab65278e77";
if let Ok(path) = get_command(command) {
panic!("Should not have found command {path:?}, but succeeded");
};
Ok(())
}
#[test]
#[cfg(target_os = "linux")]
fn detect_virt_succeeds() -> TestResult {
detect_virt()?;
Ok(())
}
}