Add a PVE::SectionConfig isolated mode test case where a property with
the same name, but differing optionality is defined on two plugins.
That is, the name is the same, but one has `optional => 1`, whereas
the other has `optional => 0`.

In both create and update schema, both properties are marked as
optional, because properties added by child plugins are always marked
as optional.

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

diff --git a/test/SectionConfig/schema_isolated_test.pl 
b/test/SectionConfig/schema_isolated_test.pl
index 4b14d8a..a94dcb1 100755
--- a/test/SectionConfig/schema_isolated_test.pl
+++ b/test/SectionConfig/schema_isolated_test.pl
@@ -303,6 +303,139 @@ package IdenticalPropertyOnDifferentPlugin {
     }
 }
 
+package SamePropertyNamesOnDifferentPlugins {
+    use base qw(TestPackage);
+
+    sub desc($class) {
+        return
+            "defining properties with the same name but different optionality"
+            . " on different plugins does not lead to 'oneOf' being used 
inside"
+            . " either createSchema or updateSchema - because properties 
defined"
+            . " by plugins are always marked as optional";
+    }
+
+    package SamePropertyNamesOnDifferentPlugins::PluginBase {
+        use base qw(PVE::SectionConfig);
+
+        my $DEFAULT_DATA = {};
+
+        sub private($class) {
+            return $DEFAULT_DATA;
+        }
+    };
+
+    package SamePropertyNamesOnDifferentPlugins::PluginOne {
+        use base qw(SamePropertyNamesOnDifferentPlugins::PluginBase);
+
+        sub type($class) {
+            return 'one';
+        }
+
+        sub properties($class) {
+            return {
+                'prop-one' => {
+                    type => 'string',
+                    optional => 0,
+                },
+                'prop-two' => {
+                    type => 'string',
+                    optional => 1,
+                },
+            };
+        }
+
+        sub options($class) {
+            return {
+                'prop-one' => {
+                    optional => 0,
+                },
+                'prop-two' => {
+                    optional => 1,
+                },
+            };
+        }
+    };
+
+    package SamePropertyNamesOnDifferentPlugins::PluginTwo {
+        use base qw(SamePropertyNamesOnDifferentPlugins::PluginBase);
+
+        sub type($class) {
+            return 'two';
+        }
+
+        sub properties($class) {
+            return {
+                'prop-one' => {
+                    type => 'string',
+                    optional => 1,
+                },
+                'prop-two' => {
+                    type => 'string',
+                    optional => 0,
+                },
+            };
+        }
+
+        sub options($class) {
+            return {
+                'prop-one' => {
+                    optional => 1,
+                },
+                'prop-two' => {
+                    optional => 0,
+                },
+            };
+        }
+    };
+
+    sub expected_isolated_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,
+                },
+            },
+        };
+    }
+
+    sub expected_isolated_updateSchema($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,
+                },
+                $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