From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 0F2B4BEDA8 for ; Tue, 2 Jan 2024 12:07:44 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E4B9515C44 for ; Tue, 2 Jan 2024 12:07:13 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 2 Jan 2024 12:07:13 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 35A2D4529B for ; Tue, 2 Jan 2024 12:07:13 +0100 (CET) From: Philipp Hufnagl To: pbs-devel@lists.proxmox.com Date: Tue, 2 Jan 2024 12:06:55 +0100 Message-Id: <20240102110655.155329-5-p.hufnagl@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240102110655.155329-1-p.hufnagl@proxmox.com> References: <20240102110655.155329-1-p.hufnagl@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.039 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup v7 4/4] tests: check if include/exclude behavior works correctly 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: , X-List-Received-Date: Tue, 02 Jan 2024 11:07:44 -0000 This checks if including and excluding works as expected. That the filter are added out of order is on purpose since it sould make no difference. Signed-off-by: Philipp Hufnagl --- tests/sync_jobs.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/sync_jobs.rs diff --git a/tests/sync_jobs.rs b/tests/sync_jobs.rs new file mode 100644 index 00000000..45b46f14 --- /dev/null +++ b/tests/sync_jobs.rs @@ -0,0 +1,76 @@ +use pbs_api_types::{BackupGroup, BackupType, GroupFilter}; +use std::str::FromStr; + +#[test] +fn test_no_filters() { + let group_filters = vec![]; + + let do_backup = vec![ + "vm/101", "vm/102", "vm/103", "vm/104", "vm/105", "vm/106", "vm/107", "vm/108", "vm/109", + ]; + + for id in do_backup { + assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters)); + } +} + +#[test] +fn test_include_filters() { + let group_filters = vec![GroupFilter::from_str("regex:.*10[2-8]").unwrap()]; + + let do_backup = vec![ + "vm/102", "vm/103", "vm/104", "vm/105", "vm/106", "vm/107", "vm/108", + ]; + + let dont_backup = vec!["vm/101", "vm/109"]; + + for id in do_backup { + assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters)); + } + + for id in dont_backup { + assert!(!BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters)); + } +} + +#[test] +fn test_exclude_filters() { + let group_filters = vec![ + GroupFilter::from_str("exclude:regex:.*10[1-3]").unwrap(), + GroupFilter::from_str("exclude:regex:.*10[5-7]").unwrap(), + ]; + + let do_backup = vec!["vm/104", "vm/108", "vm/109"]; + + let dont_backup = vec!["vm/101", "vm/102", "vm/103", "vm/105", "vm/106", "vm/107"]; + + for id in do_backup { + assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters)); + } + for id in dont_backup { + assert!(!BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters)); + } +} + +#[test] +fn test_include_and_exclude_filters() { + let group_filters = vec![ + GroupFilter::from_str("exclude:regex:.*10[1-3]").unwrap(), + GroupFilter::from_str("regex:.*10[2-8]").unwrap(), + GroupFilter::from_str("exclude:regex:.*10[5-7]").unwrap(), + ]; + + let do_backup = vec!["vm/104", "vm/108"]; + + let dont_backup = vec![ + "vm/101", "vm/102", "vm/103", "vm/105", "vm/106", "vm/107", "vm/109", + ]; + + for id in do_backup { + assert!(BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters)); + } + + for id in dont_backup { + assert!(!BackupGroup::new(BackupType::Vm, id).apply_filters(&group_filters)); + } +} -- 2.39.2