all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Lendl <s.lendl@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v3 3/9] tests: simple tests for writing the network config
Date: Thu,  4 Apr 2024 12:00:30 +0200	[thread overview]
Message-ID: <20240404100036.188225-4-s.lendl@proxmox.com> (raw)
In-Reply-To: <20240404100036.188225-1-s.lendl@proxmox.com>

Simple tests for manual and static configurations.

Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
Tested-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
---
 pbs-config/src/network/mod.rs | 79 +++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/pbs-config/src/network/mod.rs b/pbs-config/src/network/mod.rs
index 21187ec2..7fec7e29 100644
--- a/pbs-config/src/network/mod.rs
+++ b/pbs-config/src/network/mod.rs
@@ -503,3 +503,82 @@ pub fn complete_port_list(arg: &str, _param: &HashMap<String, String>) -> Vec<St
         .map(|port| format!("{}{}", prefix, port))
         .collect()
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    use NetworkConfigMethod::*;
+    use NetworkInterfaceType::*;
+    use NetworkOrderEntry::*;
+
+    #[test]
+    fn test_write_network_config_manual() {
+        let iface_name = String::from("enp3s0");
+        let mut iface = Interface::new(iface_name.clone());
+        iface.interface_type = Eth;
+        iface.method = Some(Manual);
+        iface.active = true;
+
+        let nw_config = NetworkConfig {
+            interfaces: BTreeMap::from([(iface_name.clone(), iface)]),
+            order: vec![Iface(iface_name.clone())],
+        };
+
+        assert_eq!(
+            String::try_from(nw_config).unwrap().trim(),
+            r#"iface enp3s0 inet manual"#
+        );
+    }
+
+    #[test]
+    fn test_write_network_config_static() {
+        let iface_name = String::from("enp3s0");
+        let mut iface = Interface::new(iface_name.clone());
+        iface.interface_type = Eth;
+        iface.method = Some(Static);
+        iface.cidr = Some(String::from("10.0.0.100/16"));
+        iface.active = true;
+
+        let nw_config = NetworkConfig {
+            interfaces: BTreeMap::from([(iface_name.clone(), iface)]),
+            order: vec![Iface(iface_name.clone())],
+        };
+        assert_eq!(
+            String::try_from(nw_config).unwrap().trim(),
+            format!(
+                r#"
+iface enp3s0 inet static
+	address 10.0.0.100/16"#
+            )
+            .trim()
+        );
+    }
+
+    #[test]
+    fn test_write_network_config_static_with_gateway() {
+        let iface_name = String::from("enp3s0");
+        let mut iface = Interface::new(iface_name.clone());
+        iface.interface_type = Eth;
+        iface.method = Some(Static);
+        iface.cidr = Some(String::from("10.0.0.100/16"));
+        iface.gateway = Some(String::from("10.0.0.1"));
+        iface.active = true;
+
+        let nw_config = NetworkConfig {
+            interfaces: BTreeMap::from([(iface_name.clone(), iface)]),
+            order: vec![Iface(iface_name.clone())],
+        };
+        assert_eq!(
+            String::try_from(nw_config).unwrap().trim(),
+            format!(
+                r#"
+iface enp3s0 inet static
+	address 10.0.0.100/16
+	gateway 10.0.0.1"#
+            )
+            .trim()
+        );
+    }
+}
+
-- 
2.44.0





  parent reply	other threads:[~2024-04-04 10:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-04 10:00 [pbs-devel] [PATCH widget-toolkit/proxmox-backup v3 0/9] Fix #3115: VLAN Network Interface Configuration Stefan Lendl
2024-04-04 10:00 ` [pbs-devel] [PATCH widget-toolkit v3 1/9] form: include vlan field widget from PVE Stefan Lendl
2024-04-04 10:00 ` [pbs-devel] [PATCH proxmox-backup v3 2/9] tests: move network tests to parser.rs Stefan Lendl
2024-04-04 10:00 ` Stefan Lendl [this message]
2024-04-04 10:00 ` [pbs-devel] [PATCH proxmox-backup v3 4/9] config: write vlan network interface Stefan Lendl
2024-04-04 10:00 ` [pbs-devel] [PATCH proxmox-backup v3 5/9] config: parse vlan interface from config Stefan Lendl
2024-04-04 10:00 ` [pbs-devel] [PATCH proxmox-backup v3 6/9] config: remove unnecessary pub in various methods in NetworkConfig Stefan Lendl
2024-04-04 10:00 ` [pbs-devel] [PATCH proxmox-backup v3 7/9] fmt: fix intendation in api macro Stefan Lendl
2024-04-04 10:00 ` [pbs-devel] [PATCH proxmox-backup v3 8/9] api: create and update vlan interfaces Stefan Lendl
2024-04-04 10:00 ` [pbs-devel] [PATCH proxmox-backup v3 9/9] ui: enable vlan widget Stefan Lendl
2024-04-18  9:43 ` [pbs-devel] [PATCH widget-toolkit/proxmox-backup v3 0/9] Fix #3115: VLAN Network Interface Configuration Folke Gleumes
2024-04-18 10:04   ` Folke Gleumes
2024-04-24 19:53 ` [pbs-devel] applied-series: " Thomas Lamprecht
     [not found] <20240404095151.184141-1-s.lendl@proxmox.com>
2024-04-04  9:51 ` [pbs-devel] [PATCH proxmox-backup v3 3/9] tests: simple tests for writing the network config Stefan Lendl

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=20240404100036.188225-4-s.lendl@proxmox.com \
    --to=s.lendl@proxmox.com \
    --cc=pbs-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