Add a PVE::SectionConfig isolated mode test case where an optional
default property (i.e. it's defined in `private()->{propertyList}`) is
marked as required by one plugin, but as optional by the other.In both create and update schema, such a property is marked as optional for plugins that use it, even for plugins that mark it as required. Signed-off-by: Max R. Carrara <[email protected]> --- test/SectionConfig/schema_isolated_test.pl | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/test/SectionConfig/schema_isolated_test.pl b/test/SectionConfig/schema_isolated_test.pl index a94dcb1..202e039 100755 --- a/test/SectionConfig/schema_isolated_test.pl +++ b/test/SectionConfig/schema_isolated_test.pl @@ -436,6 +436,161 @@ package SamePropertyNamesOnDifferentPlugins { } } +package OptionalCommonRequiredAndOptional { + use base qw(TestPackage); + + sub desc($class) { + return + "optional default properties not required by all plugins" + . " are optional in both schemas for plugins that use them," + . " even if a plugin marks it as required"; + } + + package OptionalCommonRequiredAndOptional::PluginBase { + use base qw(PVE::SectionConfig); + + my $DEFAULT_DATA = { + propertyList => { + common => { + type => 'string', + optional => 1, + }, + }, + }; + + sub private($class) { + return $DEFAULT_DATA; + } + }; + + package OptionalCommonRequiredAndOptional::PluginOne { + use base qw(OptionalCommonRequiredAndOptional::PluginBase); + + sub type($class) { + return 'one'; + } + + sub properties($class) { + return { + 'prop-one' => { + type => 'string', + optional => 1, + }, + }; + } + + sub options($class) { + return { + common => { + optional => 0, + }, + 'prop-one' => { + optional => 1, + }, + }; + } + }; + + package OptionalCommonRequiredAndOptional::PluginTwo { + use base qw(OptionalCommonRequiredAndOptional::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_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
