From 5bff2a1d4b79c735cb0c27ad52639644c60eae1b Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 29 Sep 2021 08:59:28 +0200 Subject: [PATCH] add test for property string verification errors --- proxmox/src/test/schema_verification.rs | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/proxmox/src/test/schema_verification.rs b/proxmox/src/test/schema_verification.rs index 6338ff63..4937de8c 100644 --- a/proxmox/src/test/schema_verification.rs +++ b/proxmox/src/test/schema_verification.rs @@ -14,6 +14,10 @@ static SIMPLE_OBJECT_SCHEMA: Schema = ObjectSchema::new( ] ).schema(); +static SIMPLE_PROPERTY_STRING_SCHEMA: Schema = StringSchema::new("simple property string") + .format(&ApiStringFormat::PropertyString(&SIMPLE_OBJECT_SCHEMA)) + .schema(); + static SIMPLE_ARRAY_SCHEMA: Schema = ArraySchema::new("String list.", &STRING_SCHEMA).schema(); static NESTED_OBJECT_SCHEMA: Schema = ObjectSchema::new( @@ -25,6 +29,14 @@ static NESTED_OBJECT_SCHEMA: Schema = ObjectSchema::new( ] ).schema(); +static NESTED_PROPERTY_SCHEMA: Schema = ObjectSchema::new( + "object with property strings", + &[ + ("ps1", false, &SIMPLE_PROPERTY_STRING_SCHEMA), + ] +).schema(); + + fn compare_error( expected: &[(&str, &str)], err: Error, @@ -129,3 +141,50 @@ fn verify_nested_object2() -> Result<(), Error> { Ok(()) } + +#[test] +fn verify_nested_property1() -> Result<(), Error> { + + let value = json!({"ps1": "abc"}); + + test_verify( + &NESTED_PROPERTY_SCHEMA, + &value, + &[ + ("ps1", "Value without key, but schema does not define a default key."), + ], + )?; + + Ok(()) +} + +#[test] +fn verify_nested_property2() -> Result<(), Error> { + let value = json!({"ps1": "abc=1"}); + + test_verify( + &NESTED_PROPERTY_SCHEMA, + &value, + &[ + ("ps1/abc", "schema does not allow additional properties."), + ], + )?; + + Ok(()) +} + +#[test] +fn verify_nested_property3() -> Result<(), Error> { + let value = json!({"ps1": ""}); + + test_verify( + &NESTED_PROPERTY_SCHEMA, + &value, + &[ + ("ps1/prop1", "parameter is missing and it is not optional."), + ("ps1/prop3", "parameter is missing and it is not optional."), + ], + )?; + + Ok(()) +}