From f6514a00ea28684af62697efd3bff27d11f41eaa Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Fri, 30 Aug 2024 19:46:32 +0100 Subject: [PATCH] Fix test compilation failures Signed-off-by: Aidan Hobson Sayers --- crates/libcontainer/src/config.rs | 11 ++++++++--- crates/libcontainer/src/container/container.rs | 12 +----------- crates/libcontainer/src/hooks.rs | 11 +++++------ 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/crates/libcontainer/src/config.rs b/crates/libcontainer/src/config.rs index e025b514d..5b3d3d992 100644 --- a/crates/libcontainer/src/config.rs +++ b/crates/libcontainer/src/config.rs @@ -106,10 +106,10 @@ mod tests { systemd_cgroup: true, container_name: container_id.to_owned(), }; - let config = YoukiConfig::from_spec(&spec, container_id)?; + let config = YoukiConfig::from_spec(&spec, Some(cgroup_config.clone()))?; assert_eq!(&config.hooks, spec.hooks()); dbg!(&config.cgroup_config); - assert_eq!(config.cgroup_config, cgroup_config); + assert_eq!(config.cgroup_config, Some(cgroup_config)); Ok(()) } @@ -118,7 +118,12 @@ mod tests { let container_id = "sample"; let tmp = tempfile::tempdir().expect("create temp dir"); let spec = Spec::default(); - let config = YoukiConfig::from_spec(&spec, container_id)?; + let cgroup_config = libcgroups::common::CgroupConfig { + cgroup_path: PathBuf::from(format!(":youki:{container_id}")), + systemd_cgroup: true, + container_name: container_id.to_owned(), + }; + let config = YoukiConfig::from_spec(&spec, Some(cgroup_config))?; config.save(&tmp)?; let act = YoukiConfig::load(&tmp)?; assert_eq!(act, config); diff --git a/crates/libcontainer/src/container/container.rs b/crates/libcontainer/src/container/container.rs index 2d55f69ed..fbe3acf5a 100644 --- a/crates/libcontainer/src/container/container.rs +++ b/crates/libcontainer/src/container/container.rs @@ -273,16 +273,6 @@ mod tests { assert_eq!(container.state.annotations, Some(annotations)); } - #[test] - fn test_get_set_systemd() { - let mut container = Container::default(); - assert!(!container.systemd()); - container.set_systemd(true); - assert!(container.systemd()); - container.set_systemd(false); - assert!(!container.systemd()); - } - #[test] fn test_get_set_creator() { let mut container = Container::default(); @@ -322,7 +312,7 @@ mod tests { let tmp_dir = tempfile::tempdir().unwrap(); use oci_spec::runtime::Spec; let spec = Spec::default(); - let config = YoukiConfig::from_spec(&spec, "123").context("convert spec to config")?; + let config = YoukiConfig::from_spec(&spec, None).context("convert spec to config")?; config.save(tmp_dir.path()).context("save config")?; let container = Container { diff --git a/crates/libcontainer/src/hooks.rs b/crates/libcontainer/src/hooks.rs index 0f243e0d7..5423d65b3 100644 --- a/crates/libcontainer/src/hooks.rs +++ b/crates/libcontainer/src/hooks.rs @@ -174,7 +174,7 @@ mod test { fn test_run_hook() -> Result<()> { { let default_container: Container = Default::default(); - run_hooks(None, Some(&default_container), None).context("Failed simple test")?; + run_hooks(None, &default_container, None).context("Failed simple test")?; } { @@ -183,7 +183,7 @@ mod test { let hook = HookBuilder::default().path("true").build()?; let hooks = Some(vec![hook]); - run_hooks(hooks.as_ref(), Some(&default_container), None).context("Failed true")?; + run_hooks(hooks.as_ref(), &default_container, None).context("Failed true")?; } { @@ -203,8 +203,7 @@ mod test { .env(vec![String::from("key=value")]) .build()?; let hooks = Some(vec![hook]); - run_hooks(hooks.as_ref(), Some(&default_container), None) - .context("Failed printenv test")?; + run_hooks(hooks.as_ref(), &default_container, None).context("Failed printenv test")?; } { @@ -222,7 +221,7 @@ mod test { ]) .build()?; let hooks = Some(vec![hook]); - run_hooks(hooks.as_ref(), Some(&default_container), Some(tmp.path())) + run_hooks(hooks.as_ref(), &default_container, Some(tmp.path())) .context("Failed pwd test")?; } @@ -246,7 +245,7 @@ mod test { .timeout(1) .build()?; let hooks = Some(vec![hook]); - match run_hooks(hooks.as_ref(), Some(&default_container), None) { + match run_hooks(hooks.as_ref(), &default_container, None) { Ok(_) => { bail!("The test expects the hook to error out with timeout. Should not execute cleanly"); }