From: Fiona Ebner <f.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 1/2] section config: add test for array schema
Date: Wed, 30 Nov 2022 14:12:29 +0100 [thread overview]
Message-ID: <20221130131230.105779-1-f.ebner@proxmox.com> (raw)
where duplicate keys are allowed.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
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
next reply other threads:[~2022-11-30 13:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-30 13:12 Fiona Ebner [this message]
2022-11-30 13:12 ` [pbs-devel] [PATCH proxmox 2/2] section config: fix handling array schema in unknown sections Fiona Ebner
2022-12-12 13:06 ` [pbs-devel] applied-series: [PATCH proxmox 1/2] section config: add test for array schema Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221130131230.105779-1-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox