all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH v3 1/5] client: repository: add tests for BackupRepository parsing
Date: Thu,  2 Apr 2026 00:48:57 +0200	[thread overview]
Message-ID: <20260401225305.4069441-2-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20260401225305.4069441-1-t.lamprecht@proxmox.com>

Add tests for the existing FromStr, Display, and new() implementations
of BackupRepository, covering URL parsing with various combinations
of user, host, port, datastore, IPv4, IPv6, and API tokens, as well
as the IPv6 bracket-wrapping behavior in the constructor.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

no changes since v2.

 pbs-client/src/backup_repo.rs | 79 +++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/pbs-client/src/backup_repo.rs b/pbs-client/src/backup_repo.rs
index 458f89dc2..45c859d67 100644
--- a/pbs-client/src/backup_repo.rs
+++ b/pbs-client/src/backup_repo.rs
@@ -115,3 +115,82 @@ impl std::str::FromStr for BackupRepository {
         })
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn parse_datastore_only() {
+        let repo: BackupRepository = "mystore".parse().unwrap();
+        assert_eq!(repo.store(), "mystore");
+        assert_eq!(repo.host(), "localhost");
+        assert_eq!(repo.port(), 8007);
+        assert_eq!(repo.auth_id().to_string(), "root@pam");
+    }
+
+    #[test]
+    fn parse_host_and_datastore() {
+        let repo: BackupRepository = "myhost:mystore".parse().unwrap();
+        assert_eq!(repo.host(), "myhost");
+        assert_eq!(repo.store(), "mystore");
+    }
+
+    #[test]
+    fn parse_full_with_port() {
+        let repo: BackupRepository = "admin@pam@backuphost:8008:tank".parse().unwrap();
+        assert_eq!(repo.auth_id().to_string(), "admin@pam");
+        assert_eq!(repo.host(), "backuphost");
+        assert_eq!(repo.port(), 8008);
+        assert_eq!(repo.store(), "tank");
+    }
+
+    #[test]
+    fn parse_ipv4_with_port() {
+        let repo: BackupRepository = "192.168.1.1:1234:mystore".parse().unwrap();
+        assert_eq!(repo.host(), "192.168.1.1");
+        assert_eq!(repo.port(), 1234);
+    }
+
+    #[test]
+    fn parse_ipv6_with_port() {
+        let repo: BackupRepository = "[ff80::1]:9007:mystore".parse().unwrap();
+        assert_eq!(repo.host(), "[ff80::1]");
+        assert_eq!(repo.port(), 9007);
+    }
+
+    #[test]
+    fn parse_api_token() {
+        let repo: BackupRepository = "user@pbs!token@myhost:mystore".parse().unwrap();
+        assert_eq!(repo.auth_id().to_string(), "user@pbs!token");
+    }
+
+    #[test]
+    fn parse_invalid_url_errors() {
+        assert!("".parse::<BackupRepository>().is_err());
+    }
+
+    #[test]
+    fn display_round_trip() {
+        for url in [
+            "mystore",
+            "myhost:mystore",
+            "admin@pam@backuphost:8008:tank",
+        ] {
+            let repo: BackupRepository = url.parse().unwrap();
+            assert_eq!(repo.to_string(), url, "round-trip failed for '{url}'");
+        }
+    }
+
+    #[test]
+    fn new_wraps_bare_ipv6_in_brackets() {
+        let repo = BackupRepository::new(None, Some("ff80::1".into()), None, "s".into());
+        assert_eq!(repo.host(), "[ff80::1]");
+    }
+
+    #[test]
+    fn new_preserves_already_bracketed_ipv6() {
+        let repo = BackupRepository::new(None, Some("[ff80::1]".into()), None, "s".into());
+        assert_eq!(repo.host(), "[ff80::1]");
+    }
+}
-- 
2.47.3





  reply	other threads:[~2026-04-01 22:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01 22:48 [PATCH v3 0/5] client: repository: add individual component parameters Thomas Lamprecht
2026-04-01 22:48 ` Thomas Lamprecht [this message]
2026-04-01 22:48 ` [PATCH v3 2/5] " Thomas Lamprecht
2026-04-02  8:54   ` Wolfgang Bumiller
2026-04-03  7:55   ` Christian Ebner
2026-04-01 22:48 ` [PATCH v3 3/5] client: migrate commands to flattened repository args Thomas Lamprecht
2026-04-02  8:54   ` Wolfgang Bumiller
2026-04-01 22:49 ` [PATCH v3 4/5] docs: document repository component options and env vars Thomas Lamprecht
2026-04-01 22:49 ` [PATCH v3 5/5] fix #5340: client: repository: add PBS_NAMESPACE environment variable Thomas Lamprecht

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=20260401225305.4069441-2-t.lamprecht@proxmox.com \
    --to=t.lamprecht@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