From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH v2 1/5] client: repository: add tests for BackupRepository parsing
Date: Mon, 30 Mar 2026 20:20:37 +0200 [thread overview]
Message-ID: <20260330182352.2346420-2-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20260330182352.2346420-1-t.lamprecht@proxmox.com>
Add tests for BackupRepository, covering URL parsing with various
combinations of user, host, port, datastore, IPv4, IPv6, and API tokens.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
new in 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
next prev parent reply other threads:[~2026-03-30 18:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 18:20 [PATCH v2 0/5] client: repository: add individual component parameters Thomas Lamprecht
2026-03-30 18:20 ` Thomas Lamprecht [this message]
2026-03-30 18:20 ` [PATCH v2 2/5] " Thomas Lamprecht
2026-03-31 8:55 ` Thomas Lamprecht
2026-03-30 18:20 ` [PATCH v2 3/5] client: migrate commands to flattened repository args Thomas Lamprecht
2026-03-30 18:20 ` [PATCH v2 4/5] docs: document repository component options and env vars Thomas Lamprecht
2026-03-30 18:20 ` [PATCH v2 5/5] fix #5340: client: repository: add PBS_NAMESPACE environment variable Thomas Lamprecht
2026-04-01 22:56 ` superseded: [PATCH v2 0/5] client: repository: add individual component parameters 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=20260330182352.2346420-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox