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 0D70CD2A0 for ; Wed, 30 Nov 2022 14:13:06 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DF8E41DEB7 for ; Wed, 30 Nov 2022 14:13:05 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 30 Nov 2022 14:13:04 +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 969F043588 for ; Wed, 30 Nov 2022 14:13:04 +0100 (CET) From: Fiona Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 30 Nov 2022 14:12:29 +0100 Message-Id: <20221130131230.105779-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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% 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 proxmox 1/2] section config: add test for array schema 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: Wed, 30 Nov 2022 13:13:06 -0000 where duplicate keys are allowed. Signed-off-by: Fiona Ebner --- proxmox-section-config/src/lib.rs | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/proxmox-section-config/src/lib.rs b/proxmox-section-config/src/lib.rs index 91793a4..929ab92 100644 --- a/proxmox-section-config/src/lib.rs +++ b/proxmox-section-config/src/lib.rs @@ -1106,6 +1106,92 @@ token: asdf@pbs!asdftoken assert!(config.parse(filename, raw).is_err()); } +#[test] +fn test_section_config_array() { + let filename = "sync.cfg"; + + const PROPERTIES: ObjectSchema = ObjectSchema::new( + "Dummy sync job properties", + &[ + ( + "group-filter", + true, + &ArraySchema::new( + "Group filter array schema", + &StringSchema::new("Group filter entry schema.").schema(), + ) + .schema(), + ), + ( + "schedule", + true, + &StringSchema::new("Remote schema.").schema(), + ), + ], + ); + + let plugin = SectionConfigPlugin::new("sync".to_string(), None, &PROPERTIES); + + const ID_SCHEMA: Schema = StringSchema::new("ID schema.").min_length(3).schema(); + + let mut config = SectionConfig::new(&ID_SCHEMA); + config.register_plugin(plugin); + + let raw = r" + +sync: s-4a1011e8-40e2 + group-filter group:vm/144 + schedule monthly + +sync: s-5b2122f9-51f3 + group-filter group:vm/100 + schedule hourly + group-filter group:vm/102 + +sync: s-6c32330a-6204 + group-filter group:vm/103 + group-filter group:vm/104 + group-filter group:vm/105 +"; + + let check = |res: SectionConfigData| { + let (_, second_section) = res.sections.get("s-5b2122f9-51f3").unwrap(); + assert_eq!(*second_section.get("schedule").unwrap(), json!("hourly")); + assert_eq!( + *second_section.get("group-filter").unwrap(), + json!(["group:vm/100", "group:vm/102"]), + ); + + let (_, third_section) = res.sections.get("s-6c32330a-6204").unwrap(); + assert_eq!( + *third_section.get("group-filter").unwrap(), + json!(["group:vm/103", "group:vm/104", "group:vm/105"]), + ); + assert!(third_section.get("schedule").is_none()); + }; + + let res = config.parse(filename, raw).unwrap(); + println!("RES: {:?}", res); + let written = config.write(filename, &res).unwrap(); + println!("CONFIG:\n{}", written); + + check(res); + + let res = config.parse(filename, &written).unwrap(); + println!("RES (second time): {:?}", res); + + check(res); + + let raw = r" + +sync: fail + schedule hourly + schedule monthly +"; + + assert!(config.parse(filename, raw).is_err()); +} + /// Generate ReST Documentaion for ``SectionConfig`` pub fn dump_section_config(config: &SectionConfig) -> String { let mut res = String::new(); -- 2.30.2