From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <p.hufnagl@proxmox.com> 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 3D721BC2B3 for <pbs-devel@lists.proxmox.com>; Fri, 22 Dec 2023 10:45:45 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 212DA1B83 for <pbs-devel@lists.proxmox.com>; Fri, 22 Dec 2023 10:45:45 +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 <pbs-devel@lists.proxmox.com>; Fri, 22 Dec 2023 10:45:44 +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 601FC48C6B for <pbs-devel@lists.proxmox.com>; Fri, 22 Dec 2023 10:45:44 +0100 (CET) Message-ID: <437a089d-e8ae-44df-b8a8-ad611f22c2c6@proxmox.com> Date: Fri, 22 Dec 2023 10:45:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Lukas Wagner <l.wagner@proxmox.com>, Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com> References: <20231218153638.609440-1-p.hufnagl@proxmox.com> <20231218153638.609440-5-p.hufnagl@proxmox.com> <79bc00aa-eb74-4c63-a757-c1fb703350bd@proxmox.com> From: Philipp Hufnagl <p.hufnagl@proxmox.com> In-Reply-To: <79bc00aa-eb74-4c63-a757-c1fb703350bd@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.041 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 <pbs-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/> List-Post: <mailto:pbs-devel@lists.proxmox.com> List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe> X-List-Received-Date: Fri, 22 Dec 2023 09:45:45 -0000 On 12/19/23 14:23, Lukas Wagner wrote: > > > 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::<GroupFilter>().unwrap(); > > The superfish (`::<Type>`) is probably not needed, since the type can > be inferred because you pass it to the split function ;) I'll try that. Thanks > >> + 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. > Yes, that makes the testing way more robust. Ill add this cases.