all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v3 proxmox-backup 5/5] api types: add unit tests for backup archive name parsing
Date: Thu, 24 Oct 2024 10:01:50 +0200	[thread overview]
Message-ID: <20241024080150.30200-6-c.ebner@proxmox.com> (raw)
In-Reply-To: <20241024080150.30200-1-c.ebner@proxmox.com>

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
changes since version 2:
- no changes since previous version

 pbs-api-types/src/datastore.rs | 55 ++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs
index 62e4f7345..97fd5266a 100644
--- a/pbs-api-types/src/datastore.rs
+++ b/pbs-api-types/src/datastore.rs
@@ -1695,3 +1695,58 @@ impl BackupArchiveName {
 impl ApiType for BackupArchiveName {
     const API_SCHEMA: Schema = BACKUP_ARCHIVE_NAME_SCHEMA;
 }
+
+#[cfg(test)]
+mod tests {
+    #[test]
+    fn test_backup_archive_name() {
+        use super::*;
+
+        // Test invalid archive names
+        let invalid_archive_names = ["/invalid/", "/invalid/.."];
+
+        for archive_name in invalid_archive_names {
+            assert!(BackupArchiveName::from_path(archive_name).is_err());
+        }
+
+        // Test valid pxar archive names
+        let valid_archive_names = [
+            "/valid/archive-name.pxar",
+            "/valid/archive-name.pxar.didx",
+            "/valid/archive-name.mpxar",
+            "/valid/archive-name.mpxar.didx",
+            "/valid/archive-name.ppxar",
+            "/valid/archive-name.ppxar.didx",
+        ];
+
+        for archive_name in valid_archive_names {
+            let archive = BackupArchiveName::from_path(archive_name).unwrap();
+            assert!(archive.as_ref().ends_with("pxar.didx"));
+            assert!(archive.without_type_extension().ends_with("pxar"));
+            assert!(archive.archive_type() == ArchiveType::DynamicIndex);
+        }
+
+        // Test valid img archive names
+        let valid_archive_names = ["/valid/archive-name.img", "/valid/archive-name.img.fidx"];
+
+        for archive_name in valid_archive_names {
+            let archive = BackupArchiveName::from_path(archive_name).unwrap();
+            assert!(archive.as_ref() == "archive-name.img.fidx");
+            assert!(archive.without_type_extension() == "archive-name.img");
+            assert!(archive.archive_type() == ArchiveType::FixedIndex);
+        }
+
+        // Test valid blob archive names
+        let valid_archive_names = [
+            "/valid/archive-name.pcat1",
+            "/valid/archive-name.pcat1.blob",
+            "/valid/archive-name.all-other-ext",
+        ];
+
+        for archive_name in valid_archive_names {
+            let archive = BackupArchiveName::from_path(archive_name).unwrap();
+            assert!(archive.as_ref().ends_with(".blob"));
+            assert!(archive.archive_type() == ArchiveType::Blob);
+        }
+    }
+}
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  parent reply	other threads:[~2024-10-24  8:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24  8:01 [pbs-devel] [PATCH v3 proxmox-backup 0/5] introduce dedcated archive name api type Christian Ebner
2024-10-24  8:01 ` [pbs-devel] [PATCH v3 proxmox-backup 1/5] datastore: move `ArchiveType` to api types Christian Ebner
2024-10-24  8:01 ` [pbs-devel] [PATCH v3 proxmox-backup 2/5] api types: introduce `BackupArchiveName` type Christian Ebner
2024-10-25 12:15   ` Fabian Grünbichler
2024-11-04 11:56     ` Christian Ebner
2024-11-04 12:23       ` Fabian Grünbichler
2024-10-24  8:01 ` [pbs-devel] [PATCH v3 proxmox-backup 3/5] client/server: use dedicated api type for all archive names Christian Ebner
2024-10-24  8:01 ` [pbs-devel] [PATCH v3 proxmox-backup 4/5] client: drop unused parse_archive_type helper Christian Ebner
2024-10-24  8:01 ` Christian Ebner [this message]
2024-10-24  9:21 ` [pbs-devel] [PATCH v3 proxmox-backup 0/5] introduce dedcated archive name api type Gabriel Goller

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=20241024080150.30200-6-c.ebner@proxmox.com \
    --to=c.ebner@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