[pbs-devel] [PATCH v3 proxmox-backup 5/5] api types: add unit tests for backup archive name parsing

Christian Ebner c.ebner at proxmox.com
Thu Oct 24 10:01:50 CEST 2024


Signed-off-by: Christian Ebner <c.ebner at 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





More information about the pbs-devel mailing list