mirror of
https://git.proxmox.com/git/pve-installer
synced 2025-04-28 12:51:31 +00:00
tui, common: move network option tests to correct crate
The `NetworkOptions` struct was moved here in5362c05cd
("common: copy common code from tui-installer") and86c48f76f
("tui: switch to common crate") but the tests were forgotten at the original place. No functional changes. Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
parent
7ac398a4b9
commit
a51f65e731
@ -31,3 +31,6 @@ http = [
|
|||||||
"dep:sha2",
|
"dep:sha2",
|
||||||
"dep:ureq"
|
"dep:ureq"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
pretty_assertions = "1.4"
|
||||||
|
@ -469,3 +469,96 @@ pub fn email_validate(email: &str) -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::{
|
||||||
|
setup::{Dns, Gateway, Interface, InterfaceState, NetworkInfo, Routes, SetupInfo},
|
||||||
|
utils::CidrAddress,
|
||||||
|
};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn network_options_from_setup_network_info() {
|
||||||
|
let setup = SetupInfo::mocked();
|
||||||
|
|
||||||
|
let mut interfaces = BTreeMap::new();
|
||||||
|
interfaces.insert(
|
||||||
|
"eth0".to_owned(),
|
||||||
|
Interface {
|
||||||
|
name: "eth0".to_owned(),
|
||||||
|
index: 0,
|
||||||
|
state: InterfaceState::Up,
|
||||||
|
mac: "01:23:45:67:89:ab".to_owned(),
|
||||||
|
addresses: Some(vec![
|
||||||
|
CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut info = NetworkInfo {
|
||||||
|
dns: Dns {
|
||||||
|
domain: Some("bar.com".to_owned()),
|
||||||
|
dns: Vec::new(),
|
||||||
|
},
|
||||||
|
routes: Some(Routes {
|
||||||
|
gateway4: Some(Gateway {
|
||||||
|
dev: "eth0".to_owned(),
|
||||||
|
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
||||||
|
}),
|
||||||
|
gateway6: None,
|
||||||
|
}),
|
||||||
|
interfaces,
|
||||||
|
hostname: Some("foo".to_owned()),
|
||||||
|
};
|
||||||
|
|
||||||
|
pretty_assertions::assert_eq!(
|
||||||
|
NetworkOptions::defaults_from(&setup, &info),
|
||||||
|
NetworkOptions {
|
||||||
|
ifname: "eth0".to_owned(),
|
||||||
|
fqdn: Fqdn::from("foo.bar.com").unwrap(),
|
||||||
|
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
||||||
|
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
||||||
|
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
info.hostname = None;
|
||||||
|
pretty_assertions::assert_eq!(
|
||||||
|
NetworkOptions::defaults_from(&setup, &info),
|
||||||
|
NetworkOptions {
|
||||||
|
ifname: "eth0".to_owned(),
|
||||||
|
fqdn: Fqdn::from("pve.bar.com").unwrap(),
|
||||||
|
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
||||||
|
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
||||||
|
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
info.dns.domain = None;
|
||||||
|
pretty_assertions::assert_eq!(
|
||||||
|
NetworkOptions::defaults_from(&setup, &info),
|
||||||
|
NetworkOptions {
|
||||||
|
ifname: "eth0".to_owned(),
|
||||||
|
fqdn: Fqdn::from("pve.example.invalid").unwrap(),
|
||||||
|
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
||||||
|
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
||||||
|
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
info.hostname = Some("foo".to_owned());
|
||||||
|
pretty_assertions::assert_eq!(
|
||||||
|
NetworkOptions::defaults_from(&setup, &info),
|
||||||
|
NetworkOptions {
|
||||||
|
ifname: "eth0".to_owned(),
|
||||||
|
fqdn: Fqdn::from("foo.example.invalid").unwrap(),
|
||||||
|
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
||||||
|
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
||||||
|
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,6 +14,3 @@ serde_json.workspace = true
|
|||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
|
|
||||||
cursive = { version = "0.21", default-features = false, features = ["crossterm-backend"] }
|
cursive = { version = "0.21", default-features = false, features = ["crossterm-backend"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
pretty_assertions = "1.4"
|
|
||||||
|
@ -79,96 +79,3 @@ impl InstallerOptions {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use proxmox_installer_common::{
|
|
||||||
setup::{Dns, Gateway, Interface, InterfaceState, NetworkInfo, Routes, SetupInfo},
|
|
||||||
utils::{CidrAddress, Fqdn},
|
|
||||||
};
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn network_options_from_setup_network_info() {
|
|
||||||
let setup = SetupInfo::mocked();
|
|
||||||
|
|
||||||
let mut interfaces = BTreeMap::new();
|
|
||||||
interfaces.insert(
|
|
||||||
"eth0".to_owned(),
|
|
||||||
Interface {
|
|
||||||
name: "eth0".to_owned(),
|
|
||||||
index: 0,
|
|
||||||
state: InterfaceState::Up,
|
|
||||||
mac: "01:23:45:67:89:ab".to_owned(),
|
|
||||||
addresses: Some(vec![
|
|
||||||
CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut info = NetworkInfo {
|
|
||||||
dns: Dns {
|
|
||||||
domain: Some("bar.com".to_owned()),
|
|
||||||
dns: Vec::new(),
|
|
||||||
},
|
|
||||||
routes: Some(Routes {
|
|
||||||
gateway4: Some(Gateway {
|
|
||||||
dev: "eth0".to_owned(),
|
|
||||||
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
|
||||||
}),
|
|
||||||
gateway6: None,
|
|
||||||
}),
|
|
||||||
interfaces,
|
|
||||||
hostname: Some("foo".to_owned()),
|
|
||||||
};
|
|
||||||
|
|
||||||
pretty_assertions::assert_eq!(
|
|
||||||
NetworkOptions::defaults_from(&setup, &info),
|
|
||||||
NetworkOptions {
|
|
||||||
ifname: "eth0".to_owned(),
|
|
||||||
fqdn: Fqdn::from("foo.bar.com").unwrap(),
|
|
||||||
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
|
||||||
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
|
||||||
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
info.hostname = None;
|
|
||||||
pretty_assertions::assert_eq!(
|
|
||||||
NetworkOptions::defaults_from(&setup, &info),
|
|
||||||
NetworkOptions {
|
|
||||||
ifname: "eth0".to_owned(),
|
|
||||||
fqdn: Fqdn::from("pve.bar.com").unwrap(),
|
|
||||||
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
|
||||||
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
|
||||||
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
info.dns.domain = None;
|
|
||||||
pretty_assertions::assert_eq!(
|
|
||||||
NetworkOptions::defaults_from(&setup, &info),
|
|
||||||
NetworkOptions {
|
|
||||||
ifname: "eth0".to_owned(),
|
|
||||||
fqdn: Fqdn::from("pve.example.invalid").unwrap(),
|
|
||||||
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
|
||||||
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
|
||||||
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
info.hostname = Some("foo".to_owned());
|
|
||||||
pretty_assertions::assert_eq!(
|
|
||||||
NetworkOptions::defaults_from(&setup, &info),
|
|
||||||
NetworkOptions {
|
|
||||||
ifname: "eth0".to_owned(),
|
|
||||||
fqdn: Fqdn::from("foo.example.invalid").unwrap(),
|
|
||||||
address: CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
|
|
||||||
gateway: IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)),
|
|
||||||
dns_server: Ipv4Addr::UNSPECIFIED.into(),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user