Skip to content

Commit

Permalink
add a unit test for fork.
Browse files Browse the repository at this point in the history
  • Loading branch information
utam0k committed Oct 21, 2021
1 parent ea3d37d commit 41cbf8e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/process/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,23 @@ pub fn container_fork<F: FnOnce() -> Result<()>>(cb: F) -> Result<Pid> {
}
}
}

#[cfg(test)]
mod test {
use super::*;
use anyhow::{bail, Result};
use nix::sys::wait::{waitpid, WaitStatus};

#[test]
fn test_container_fork() -> Result<()> {
let pid = container_fork(|| Ok(()))?;
match waitpid(pid, None).expect("wait pid failed.") {
WaitStatus::Exited(p, status) => {
assert_eq!(pid, p);
assert_eq!(status, 0);
Ok(())
}
_ => bail!("test failed"),
}
}
}

0 comments on commit 41cbf8e

Please sign in to comment.