mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
test: Add test to verify try_from for clh Netconfig
Add tests to verify conversion from runtime NetworkConfig to clh specific config. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
9049d311df
commit
9c233bb9e0
@ -247,3 +247,44 @@ impl TryFrom<ShareFsSettings> for FsConfig {
|
|||||||
Ok(fs_cfg)
|
Ok(fs_cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::Address;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_networkconfig_to_netconfig() {
|
||||||
|
let mut cfg = NetworkConfig {
|
||||||
|
host_dev_name: String::from("tap0"),
|
||||||
|
virt_iface_name: String::from("eth0"),
|
||||||
|
queue_size: 256,
|
||||||
|
queue_num: 2,
|
||||||
|
guest_mac: None,
|
||||||
|
index: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let net = NetConfig::try_from(cfg.clone());
|
||||||
|
assert_eq!(
|
||||||
|
net.unwrap_err().to_string(),
|
||||||
|
"Missing mac address for network device"
|
||||||
|
);
|
||||||
|
|
||||||
|
let v: [u8; 6] = [10, 11, 128, 3, 4, 5];
|
||||||
|
let mac_address = Address(v);
|
||||||
|
cfg.guest_mac = Some(mac_address.clone());
|
||||||
|
|
||||||
|
let expected = NetConfig {
|
||||||
|
tap: Some(cfg.host_dev_name.clone()),
|
||||||
|
id: Some(cfg.virt_iface_name.clone()),
|
||||||
|
num_queues: cfg.queue_num,
|
||||||
|
queue_size: cfg.queue_size as u16,
|
||||||
|
mac: MacAddr { bytes: v },
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let net = NetConfig::try_from(cfg);
|
||||||
|
assert!(net.is_ok());
|
||||||
|
assert_eq!(net.unwrap(), expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user