Add a PVE::SectionConfig test case for plugin systems that declare a
default property as required (in `private()->{propertyList}`), but
mark it as optional in all child plugins (i.e. in their `options()`
methods).

In unified mode, such properties remain marked as *required* in both
create and update schema.

In isolated mode, such properties are marked as *optional* in both
create and update schema.

Signed-off-by: Max R. Carrara <[email protected]>
---
 test/SectionConfig/schema_comparison_test.pl | 204 +++++++++++++++++++
 1 file changed, 204 insertions(+)

diff --git a/test/SectionConfig/schema_comparison_test.pl 
b/test/SectionConfig/schema_comparison_test.pl
index 97f4820..3ae8551 100755
--- a/test/SectionConfig/schema_comparison_test.pl
+++ b/test/SectionConfig/schema_comparison_test.pl
@@ -1746,6 +1746,210 @@ package RequiredCommonRequiredByAll {
     }
 }
 
+package RequiredCommonOptionalForAll {
+    use base qw(TestPackage);
+
+    sub desc($class) {
+        return
+            "in unified mode, required default properties remain required in"
+            . " both schemas, even if declared as optional"
+            . " - in isolated mode, these properties are optional in both 
schemas";
+    }
+
+    package RequiredCommonOptionalForAll::PluginBase {
+        use base qw(PVE::SectionConfig);
+
+        my $DEFAULT_DATA = {
+            propertyList => {
+                common => {
+                    type => 'string',
+                    optional => 0,
+                },
+            },
+        };
+
+        sub private($class) {
+            return $DEFAULT_DATA;
+        }
+    };
+
+    package RequiredCommonOptionalForAll::PluginOne {
+        use base qw(RequiredCommonOptionalForAll::PluginBase);
+
+        sub type($class) {
+            return 'one';
+        }
+
+        sub properties($class) {
+            return {
+                'prop-one' => {
+                    type => 'string',
+                    optional => 1,
+                },
+            };
+        }
+
+        sub options($class) {
+            return {
+                common => {
+                    optional => 1,
+                },
+                'prop-one' => {
+                    optional => 1,
+                },
+            };
+        }
+    };
+
+    package RequiredCommonOptionalForAll::PluginTwo {
+        use base qw(RequiredCommonOptionalForAll::PluginBase);
+
+        sub type($class) {
+            return 'two';
+        }
+
+        sub properties($class) {
+            return {
+                'prop-two' => {
+                    type => 'string',
+                    optional => 1,
+                },
+            };
+        }
+
+        sub options($class) {
+            return {
+                common => {
+                    optional => 1,
+                },
+                'prop-two' => {
+                    optional => 1,
+                },
+            };
+        }
+    };
+
+    sub expected_unified_createSchema($class) {
+        return {
+            type => 'object',
+            additionalProperties => 0,
+            properties => {
+                type => {
+                    type => 'string',
+                    enum => [
+                        "one", "two",
+                    ],
+                },
+                'prop-one' => {
+                    type => 'string',
+                    optional => 1,
+                },
+                'prop-two' => {
+                    type => 'string',
+                    optional => 1,
+                },
+                'common' => {
+                    type => 'string',
+                    optional => 0,
+                },
+            },
+        };
+    }
+
+    sub expected_unified_updateSchema($class) {
+        return {
+            type => 'object',
+            additionalProperties => 0,
+            properties => {
+                'prop-one' => {
+                    type => 'string',
+                    optional => 1,
+                },
+                'prop-two' => {
+                    type => 'string',
+                    optional => 1,
+                },
+                common => {
+                    type => 'string',
+                    optional => 0,
+                },
+                $SectionConfig::Helpers::UPDATE_SCHEMA_DEFAULT_PROPERTIES->%*,
+            },
+        };
+    }
+
+    sub expected_isolated_createSchema($class) {
+        return {
+            type => 'object',
+            additionalProperties => 0,
+            properties => {
+                type => {
+                    type => 'string',
+                    enum => [
+                        "one", "two",
+                    ],
+                },
+                'prop-one' => {
+                    'instance-types' => [
+                        "one",
+                    ],
+                    'type-property' => 'type',
+                    type => 'string',
+                    optional => 1,
+                },
+                'prop-two' => {
+                    'instance-types' => [
+                        "two",
+                    ],
+                    'type-property' => 'type',
+                    type => 'string',
+                    optional => 1,
+                },
+                'common' => {
+                    type => 'string',
+                    optional => 1,
+                },
+            },
+        };
+    }
+
+    sub expected_isolated_updateSchema($class) {
+        return {
+            type => 'object',
+            additionalProperties => 0,
+            properties => {
+                type => {
+                    type => 'string',
+                    enum => [
+                        "one", "two",
+                    ],
+                },
+                'prop-one' => {
+                    'instance-types' => [
+                        "one",
+                    ],
+                    'type-property' => 'type',
+                    type => 'string',
+                    optional => 1,
+                },
+                'prop-two' => {
+                    'instance-types' => [
+                        "two",
+                    ],
+                    'type-property' => 'type',
+                    type => 'string',
+                    optional => 1,
+                },
+                common => {
+                    type => 'string',
+                    optional => 1,
+                },
+                $SectionConfig::Helpers::UPDATE_SCHEMA_DEFAULT_PROPERTIES->%*,
+            },
+        };
+    }
+}
+
 sub test_compare_deeply($got, $expected, $test_name, $test_package) {
     $test_name = "$test_package - $test_name";
     my $description = $test_package->desc();
-- 
2.47.3



_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to