From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 5/5] tui: add some tests for `NetworkInfo` -> `NetworkOptions` conversion
Date: Fri, 20 Oct 2023 11:46:48 +0200 [thread overview]
Message-ID: <20231020094651.432513-6-c.heiss@proxmox.com> (raw)
In-Reply-To: <20231020094651.432513-1-c.heiss@proxmox.com>
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
proxmox-tui-installer/src/options.rs | 110 ++++++++++++++++++++++++++-
proxmox-tui-installer/src/utils.rs | 2 +-
2 files changed, 110 insertions(+), 2 deletions(-)
diff --git a/proxmox-tui-installer/src/options.rs b/proxmox-tui-installer/src/options.rs
index 9e54da7..d4614aa 100644
--- a/proxmox-tui-installer/src/options.rs
+++ b/proxmox-tui-installer/src/options.rs
@@ -328,7 +328,7 @@ impl Default for PasswordOptions {
}
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
pub struct NetworkOptions {
pub ifname: String,
pub fqdn: Fqdn,
@@ -450,3 +450,111 @@ impl InstallerOptions {
]
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::setup::{
+ Dns, Gateway, Interface, IsoInfo, IsoLocations, NetworkInfo, ProductConfig, ProxmoxProduct,
+ Routes, SetupInfo,
+ };
+ use std::{collections::HashMap, path::PathBuf};
+
+ fn fill_setup_info() {
+ crate::init_setup_info(SetupInfo {
+ config: ProductConfig {
+ fullname: "Proxmox VE".to_owned(),
+ product: ProxmoxProduct::PVE,
+ enable_btrfs: true,
+ },
+ iso_info: IsoInfo {
+ release: String::new(),
+ isorelease: String::new(),
+ },
+ locations: IsoLocations {
+ iso: PathBuf::new(),
+ },
+ });
+ }
+
+ #[test]
+ fn network_options_from_setup_network_info() {
+ fill_setup_info();
+
+ let mut interfaces = HashMap::new();
+ interfaces.insert(
+ "eth0".to_owned(),
+ Interface {
+ name: "eth0".to_owned(),
+ index: 0,
+ 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()),
+ };
+
+ assert_eq!(
+ NetworkOptions::from(&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;
+ assert_eq!(
+ NetworkOptions::from(&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;
+ assert_eq!(
+ NetworkOptions::from(&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());
+ assert_eq!(
+ NetworkOptions::from(&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(),
+ }
+ );
+ }
+}
diff --git a/proxmox-tui-installer/src/utils.rs b/proxmox-tui-installer/src/utils.rs
index 516f9c6..89349ed 100644
--- a/proxmox-tui-installer/src/utils.rs
+++ b/proxmox-tui-installer/src/utils.rs
@@ -33,7 +33,7 @@ pub enum CidrAddressParseError {
/// assert_eq!(ipv4.to_string(), "192.168.0.1/24");
/// assert_eq!(ipv6.to_string(), "2001:db8::c0a8:1/32");
/// ```
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
pub struct CidrAddress {
addr: IpAddr,
mask: usize,
--
2.42.0
next prev parent reply other threads:[~2023-10-20 9:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 9:46 [pve-devel] [PATCH installer 0/5] use hostname from DHCP lease if available Christoph Heiss
2023-10-20 9:46 ` [pve-devel] [PATCH installer 1/5] net: move hostname/fqdn regexes into common code Christoph Heiss
2023-10-20 9:46 ` [pve-devel] [PATCH installer 2/5] run env: retrieve and store hostname from DHCP lease if available Christoph Heiss
2023-10-20 9:46 ` [pve-devel] [PATCH installer 3/5] proxinstall: use hostname from run env " Christoph Heiss
2023-10-20 9:46 ` [pve-devel] [PATCH installer 4/5] tui: " Christoph Heiss
2023-10-20 9:46 ` Christoph Heiss [this message]
2023-10-20 15:21 ` [pve-devel] applied-series: [PATCH installer 0/5] use hostname from DHCP lease " Thomas Lamprecht
2023-10-24 7:45 ` Christoph Heiss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231020094651.432513-6-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal