Skip to content

Commit

Permalink
Fix test compilation failures
Browse files Browse the repository at this point in the history
Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
  • Loading branch information
aidanhs committed Aug 30, 2024
1 parent 34b77ec commit f6514a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
11 changes: 8 additions & 3 deletions crates/libcontainer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand All @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions crates/libcontainer/src/container/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 5 additions & 6 deletions crates/libcontainer/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
}

{
Expand All @@ -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")?;
}

{
Expand All @@ -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")?;
}

{
Expand All @@ -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")?;
}

Expand All @@ -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");
}
Expand Down

0 comments on commit f6514a0

Please sign in to comment.