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 3258EBBCC6 for ; Tue, 19 Dec 2023 14:23:16 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1BFB237E45 for ; Tue, 19 Dec 2023 14:23:16 +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, 19 Dec 2023 14:23:15 +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 CAFA3485BB for ; Tue, 19 Dec 2023 14:23:14 +0100 (CET) Message-ID: <79bc00aa-eb74-4c63-a757-c1fb703350bd@proxmox.com> Date: Tue, 19 Dec 2023 14:23:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Lukas Wagner To: Proxmox Backup Server development discussion , Philipp Hufnagl References: <20231218153638.609440-1-p.hufnagl@proxmox.com> <20231218153638.609440-5-p.hufnagl@proxmox.com> Content-Language: de-AT, en-US In-Reply-To: <20231218153638.609440-5-p.hufnagl@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.004 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: Re: [pbs-devel] [PATCH proxmox-backup v5 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, 19 Dec 2023 13:23:16 -0000 On 12/18/23 16:36, Philipp Hufnagl wrote: > diff --git a/tests/sync_jobs.rs b/tests/sync_jobs.rs > new file mode 100644 > index 00000000..83877160 > --- /dev/null > +++ b/tests/sync_jobs.rs > @@ -0,0 +1,34 @@ > +use pbs_api_types::{ > + apply_filters, split_by_include_exclude, BackupGroup, BackupType, GroupFilter, > +}; > +use std::str::FromStr; > + > +#[test] > +fn test_group_filters() { > + let group_filters = vec![ > + GroupFilter::from_str("exclude:regex:.*10[1-3]").unwrap(), Just FIY, since GroupFilter implements FromStr, you can use the .parse method on the string: "...".parse::().unwrap(); The superfish (`::`) is probably not needed, since the type can be inferred because you pass it to the split function ;) > + GroupFilter::from_str("regex:.*10[2-8]").unwrap(), > + GroupFilter::from_str("exclude:regex:.*10[5-7]").unwrap(), > + ]; > + let (include_filters, exclude_filters) = split_by_include_exclude(Some(group_filters)); > + > + let dont_backup = vec![ > + "vm/101", "vm/102", "vm/103", "vm/105", "vm/106", "vm/107", "vm/109", > + ]; > + for id in dont_backup { > + assert!(!apply_filters( > + &BackupGroup::new(BackupType::Vm, id), > + &include_filters, > + &exclude_filters > + )); > + } > + > + let do_backup = vec!["vm/104", "vm/108"]; > + for id in do_backup { > + assert!(apply_filters( > + &BackupGroup::new(BackupType::Vm, id), > + &include_filters, > + &exclude_filters > + )); > + } > +} Including tests is a great idea! I'd also add tests for all four cases: - no filters - only includes - only excludes - both Right now, you've only covered the 'both' case. -- - Lukas