Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #527 from devimc/2020-08-13/unittest/rustjail-process
agent: add unit tests for rustjail/process.rs
  • Loading branch information
Julio Montes committed Aug 18, 2020
2 parents 646148b + d0a4563 commit 2d28043
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/agent/rustjail/src/process.rs
Expand Up @@ -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")
Expand All @@ -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());
}
}

0 comments on commit 2d28043

Please sign in to comment.