mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
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:
parent
c1d3e8f7fa
commit
d0a45637ba
@ -130,10 +130,8 @@ fn create_extended_pipe(flags: OFlag, pipe_size: i32) -> Result<(RawFd, RawFd)>
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::process::create_extended_pipe;
|
use super::*;
|
||||||
use nix::fcntl::{fcntl, FcntlArg, OFlag};
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::os::unix::io::RawFd;
|
|
||||||
|
|
||||||
fn get_pipe_max_size() -> i32 {
|
fn get_pipe_max_size() -> i32 {
|
||||||
fs::read_to_string("/proc/sys/fs/pipe-max-size")
|
fs::read_to_string("/proc/sys/fs/pipe-max-size")
|
||||||
@ -158,4 +156,29 @@ mod tests {
|
|||||||
let actual_size = get_pipe_size(w);
|
let actual_size = get_pipe_size(w);
|
||||||
assert_eq!(max_size, actual_size);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user