mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-24 18:27:10 +00:00
runtime-rs: Add tests for persist api for clh
Add tests to check clh struct is saved/restored correctly. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
committed by
Archana Shinde
parent
0b78296dca
commit
b3c74411f6
@@ -188,3 +188,43 @@ impl Persist for CloudHypervisorInner {
|
||||
Ok(ch)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use kata_sys_util::protection::TDXDetails;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_save_clh() {
|
||||
let mut clh = CloudHypervisorInner::new();
|
||||
clh.id = String::from("123456");
|
||||
clh.netns = Some(String::from("/var/run/netns/testnet"));
|
||||
clh.vm_path = String::from("/opt/kata/bin/cloud-hypervisor");
|
||||
clh.run_dir = String::from("/var/run/kata-containers/") + &clh.id;
|
||||
|
||||
let details = TDXDetails {
|
||||
major_version: 1,
|
||||
minor_version: 0,
|
||||
};
|
||||
|
||||
clh.guest_protection_to_use = GuestProtection::Tdx(details);
|
||||
|
||||
let state = clh.save().await.unwrap();
|
||||
assert_eq!(state.id, clh.id);
|
||||
assert_eq!(state.netns, clh.netns);
|
||||
assert_eq!(state.vm_path, clh.vm_path);
|
||||
assert_eq!(state.run_dir, clh.run_dir);
|
||||
assert_eq!(state.guest_protection_to_use, clh.guest_protection_to_use);
|
||||
assert_eq!(state.jailed, false);
|
||||
assert_eq!(state.hypervisor_type, HYPERVISOR_NAME_CH.to_string());
|
||||
|
||||
let clh = CloudHypervisorInner::restore((), state.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(clh.id, state.id);
|
||||
assert_eq!(clh.netns, state.netns);
|
||||
assert_eq!(clh.vm_path, state.vm_path);
|
||||
assert_eq!(clh.run_dir, state.run_dir);
|
||||
assert_eq!(clh.guest_protection_to_use, state.guest_protection_to_use);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user