agent: add unit tests for rustjail/process.rs

Increase code coverage to 80.9%

fixes #285

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2020-08-13 15:46:46 -05:00
parent c1d3e8f7fa
commit d0a45637ba

View File

@ -130,10 +130,8 @@ fn create_extended_pipe(flags: OFlag, pipe_size: i32) -> Result<(RawFd, RawFd)>
#[cfg(test)]
mod tests {
use crate::process::create_extended_pipe;
use nix::fcntl::{fcntl, FcntlArg, OFlag};
use super::*;
use std::fs;
use std::os::unix::io::RawFd;
fn get_pipe_max_size() -> i32 {
fs::read_to_string("/proc/sys/fs/pipe-max-size")
@ -158,4 +156,29 @@ mod tests {
let actual_size = get_pipe_size(w);
assert_eq!(max_size, actual_size);
}
#[test]
fn test_process() {
let id = "abc123rgb";
let init = true;
let process = Process::new(
&Logger::root(slog::Discard, o!("source" => "unit-test")),
&OCIProcess::default(),
id,
init,
32,
);
let mut process = process.unwrap();
assert_eq!(process.exec_id, id);
assert_eq!(process.init, init);
// -1 by default
assert_eq!(process.pid, -1);
assert!(process.wait().is_err());
// signal to every process in the process
// group of the calling process.
process.pid = 0;
assert!(process.signal(Signal::SIGCONT).is_ok());
}
}