From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id BED061FF163 for ; Thu, 24 Oct 2024 10:02:02 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8BD1098E8; Thu, 24 Oct 2024 10:02:43 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Thu, 24 Oct 2024 10:01:50 +0200 Message-Id: <20241024080150.30200-6-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241024080150.30200-1-c.ebner@proxmox.com> References: <20241024080150.30200-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH v3 proxmox-backup 5/5] api types: add unit tests for backup archive name parsing X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Signed-off-by: Christian Ebner --- 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