From c84b5e9a36bbca70c1dbc9267de328331ce186af Mon Sep 17 00:00:00 2001 From: utam0k Date: Thu, 2 Sep 2021 23:04:35 +0900 Subject: [PATCH] add basic tests for container struct. --- src/container/container.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/container/container.rs b/src/container/container.rs index b4e33d87a..cb38abb6c 100644 --- a/src/container/container.rs +++ b/src/container/container.rs @@ -56,6 +56,7 @@ impl Container { pub fn status(&self) -> ContainerStatus { self.state.status } + pub fn refresh_status(&mut self) -> Result { let new_status = match self.pid() { Some(pid) => { @@ -200,3 +201,35 @@ impl Container { Spec::load(self.root.join("config.json")) } } + +#[cfg(test)] +mod tests { + use std::env; + + use super::*; + use anyhow::Result; + + #[test] + fn test_set_id() -> Result<()> { + let dir = env::temp_dir(); + let container = Container::new("container_id", ContainerStatus::Created, None, &dir, &dir)?; + let container = container.set_pid(1); + assert_eq!(container.pid(), Some(Pid::from_raw(1))); + Ok(()) + } + + #[test] + fn test_basic_getter() -> Result<()> { + let container = Container::new( + "container_id", + ContainerStatus::Created, + None, + &PathBuf::from("."), + &PathBuf::from("."), + )?; + + assert_eq!(container.bundle(), &PathBuf::from(".")); + assert_eq!(container.root, fs::canonicalize(PathBuf::from("."))?); + Ok(()) + } +}