Skip to content

Commit

Permalink
add basic tests for container struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
utam0k committed Sep 2, 2021
1 parent fee0e76 commit c84b5e9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/container/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Container {
pub fn status(&self) -> ContainerStatus {
self.state.status
}

pub fn refresh_status(&mut self) -> Result<Self> {
let new_status = match self.pid() {
Some(pid) => {
Expand Down Expand Up @@ -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(())
}
}

0 comments on commit c84b5e9

Please sign in to comment.