all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager v4 16/21] tests: add example tests for SDN API routes
Date: Thu,  3 Sep 2026 08:50:11 +0200	[thread overview]
Message-ID: <20260903065016.31726-17-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260903065016.31726-1-l.wagner@proxmox.com>

Using the previously added dependency-injected abstractions for
accessing remotes and clients, and by using the test helpers, we can now
fairly trivially create test cases that call the API handler directly.

These tests also demonstrate how previously captured API responses from
real PVE nodes can be used to build test cases.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 server/src/api/sdn/vnets.rs                   |  2 +-
 .../pve/remote-a/list_vnets.json              |  8 ++
 .../pve/remote-a/list_zones.json              |  8 ++
 .../pve/remote-b/list_vnets.json              |  8 ++
 .../pve/remote-b/list_zones.json              |  8 ++
 server/tests/test_sdn.rs                      | 86 +++++++++++++++++++
 6 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 server/tests/api_responses/pve/remote-a/list_vnets.json
 create mode 100644 server/tests/api_responses/pve/remote-a/list_zones.json
 create mode 100644 server/tests/api_responses/pve/remote-b/list_vnets.json
 create mode 100644 server/tests/api_responses/pve/remote-b/list_zones.json
 create mode 100644 server/tests/test_sdn.rs

diff --git a/server/src/api/sdn/vnets.rs b/server/src/api/sdn/vnets.rs
index 312d46b6..e42fcab7 100644
--- a/server/src/api/sdn/vnets.rs
+++ b/server/src/api/sdn/vnets.rs
@@ -59,7 +59,7 @@ pub const ROUTER: Router = Router::new()
     }
 )]
 /// Query VNets of PVE remotes with optional filtering options
-async fn list_vnets(
+pub async fn list_vnets(
     pending: Option<bool>,
     running: Option<bool>,
     remotes: Option<HashSet<String>>,
diff --git a/server/tests/api_responses/pve/remote-a/list_vnets.json b/server/tests/api_responses/pve/remote-a/list_vnets.json
new file mode 100644
index 00000000..a105de13
--- /dev/null
+++ b/server/tests/api_responses/pve/remote-a/list_vnets.json
@@ -0,0 +1,8 @@
+[
+   {
+      "digest" : "3458032372eb62efb730fec12b34d36627a9e6e8",
+      "type" : "vnet",
+      "vnet" : "aaaavnet",
+      "zone" : "aaaa"
+   }
+]
diff --git a/server/tests/api_responses/pve/remote-a/list_zones.json b/server/tests/api_responses/pve/remote-a/list_zones.json
new file mode 100644
index 00000000..f7932bd9
--- /dev/null
+++ b/server/tests/api_responses/pve/remote-a/list_zones.json
@@ -0,0 +1,8 @@
+[
+   {
+      "digest" : "142f8be078a0fb61fa28a89cffdb17f64b05e3f9",
+      "ipam" : "pve",
+      "type" : "simple",
+      "zone" : "aaaa"
+   }
+]
diff --git a/server/tests/api_responses/pve/remote-b/list_vnets.json b/server/tests/api_responses/pve/remote-b/list_vnets.json
new file mode 100644
index 00000000..4a59edc7
--- /dev/null
+++ b/server/tests/api_responses/pve/remote-b/list_vnets.json
@@ -0,0 +1,8 @@
+[
+   {
+      "digest" : "56e0d24671dca1e6cc30a2cfdfab79a037e66a44",
+      "type" : "vnet",
+      "vnet" : "bbbbvnet",
+      "zone" : "bbbb"
+   }
+]
diff --git a/server/tests/api_responses/pve/remote-b/list_zones.json b/server/tests/api_responses/pve/remote-b/list_zones.json
new file mode 100644
index 00000000..75fd763a
--- /dev/null
+++ b/server/tests/api_responses/pve/remote-b/list_zones.json
@@ -0,0 +1,8 @@
+[
+   {
+      "digest" : "bd994284b5d766ab58b5cb69f7363153d42816f7",
+      "ipam" : "pve",
+      "type" : "simple",
+      "zone" : "bbbb"
+   }
+]
diff --git a/server/tests/test_sdn.rs b/server/tests/test_sdn.rs
new file mode 100644
index 00000000..204a94cd
--- /dev/null
+++ b/server/tests/test_sdn.rs
@@ -0,0 +1,86 @@
+use pve_api_types::{ListZonesType, SdnVnet, SdnVnetType, SdnZone};
+use server::context::ContextFactory;
+
+use crate::common::{TestApplication, rpcenv};
+
+pub mod common;
+
+common::test_pve_client!(SdnPveClient {
+    async fn list_zones(
+        &self,
+        _pending: Option<bool>,
+        _running: Option<bool>,
+        _ty: Option<ListZonesType>,
+    ) -> Result<Vec<SdnZone>, proxmox_client::Error> {
+        common::read_captured_response(&format!(
+            "tests/api_responses/pve/{}/list_zones.json",
+            self.remote(),
+        )).await
+    }
+
+    async fn list_vnets(
+        &self,
+        _pending: Option<bool>,
+        _running: Option<bool>,
+    ) -> Result<Vec<SdnVnet>, proxmox_client::Error> {
+        common::read_captured_response(&format!(
+            "tests/api_responses/pve/{}/list_vnets.json",
+            self.remote(),
+        )).await
+    }
+});
+
+#[tokio::test]
+async fn test_lists_zones() {
+    common::test_setup();
+
+    let test_app = TestApplication::new()
+        .with_pve_remote("remote-a", Default::default(), SdnPveClient)
+        .with_pve_remote("remote-b", Default::default(), SdnPveClient);
+
+    let app = test_app.make_pdm_application().unwrap();
+
+    let mut result =
+        server::api::sdn::zones::list_zones(None, None, None, None, &mut rpcenv(), app)
+            .await
+            .unwrap();
+
+    // We don't guarantee any ordering
+    result.sort_by(|a, b| a.remote.cmp(&b.remote));
+
+    assert_eq!(result.len(), 2);
+
+    assert_eq!(result[0].remote, "remote-a");
+    assert_eq!(result[0].zone.zone, "aaaa");
+    assert_eq!(result[0].zone.ty, ListZonesType::Simple);
+    assert_eq!(result[1].remote, "remote-b");
+    assert_eq!(result[1].zone.zone, "bbbb");
+    assert_eq!(result[1].zone.ty, ListZonesType::Simple);
+}
+
+#[tokio::test]
+async fn test_lists_vnets() {
+    common::test_setup();
+
+    let test_app = TestApplication::new()
+        .with_pve_remote("remote-a", Default::default(), SdnPveClient)
+        .with_pve_remote("remote-b", Default::default(), SdnPveClient);
+
+    let app = test_app.make_pdm_application().unwrap();
+
+    let mut result = server::api::sdn::vnets::list_vnets(None, None, None, &mut rpcenv(), app)
+        .await
+        .unwrap();
+
+    // We don't guarantee any ordering
+    result.sort_by(|a, b| a.remote.cmp(&b.remote));
+
+    assert_eq!(result.len(), 2);
+
+    assert_eq!(result[0].remote, "remote-a");
+    assert_eq!(result[0].vnet.vnet, "aaaavnet");
+    assert_eq!(result[0].vnet.ty, SdnVnetType::Vnet);
+    assert_eq!(result[1].remote, "remote-b");
+    assert_eq!(result[1].vnet.vnet, "bbbbvnet");
+    assert_eq!(result[1].vnet.ty, SdnVnetType::Vnet);
+}
-- 
2.47.3





  parent reply	other threads:[~2026-09-03  6:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  6:49 [PATCH datacenter-manager/proxmox v4 00/21] inject application context via API macro for easier integration testing Lukas Wagner
2026-09-03  6:49 ` [PATCH proxmox v4 01/21] router: introduce shared state Lukas Wagner
2026-09-03  6:49 ` [PATCH proxmox v4 02/21] rest-server: allow to inject " Lukas Wagner
2026-09-03  6:49 ` [PATCH proxmox v4 03/21] api-macro: support shared state extraction type Lukas Wagner
2026-09-03  8:25   ` Lukas Wagner
2026-09-03  6:49 ` [PATCH proxmox v4 04/21] product-config: add ProductConfig type Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 05/21] context: promote context to a dir-style module Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 06/21] pdm-config: remotes: rename trait methods to read/write/lock Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 07/21] pdm-config: subscriptions: " Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 08/21] remote iterator: pass remote config reader explicitly Lukas Wagner
2026-09-03  9:33   ` Michael Köppl
2026-09-03  9:41     ` Michael Köppl
2026-09-03  6:50 ` [PATCH datacenter-manager v4 09/21] context: introduce a ContextFactory to build application context Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 10/21] context: establish PdmApplication object Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 11/21] context: register PdmApplication in router Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 12/21] connection: use client factory from PdmApplication handle Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 13/21] parallel fetcher: pass arguments to closure in a single type Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 14/21] server: migrate existing ParallelFetcher users to use PdmApplication Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 15/21] tests: add helpers for building API-handler-level integration tests Lukas Wagner
2026-09-03  6:50 ` Lukas Wagner [this message]
2026-09-03  6:50 ` [PATCH datacenter-manager v4 17/21] api-cache: add wrapper type Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 18/21] context: provide api-cache on the app object Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 19/21] api: subscriptions: use PdmApplication instead of globals Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 20/21] pdm-config: subscriptions: drop unused accessor functions Lukas Wagner
2026-09-03  6:50 ` [PATCH datacenter-manager v4 21/21] tests: add example tests for remote subscription management Lukas Wagner
2026-09-03 11:17 ` superseded: [PATCH datacenter-manager/proxmox v4 00/21] inject application context via API macro for easier integration testing Lukas Wagner

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=20260903065016.31726-17-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-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