[pve-devel] [PATCH pve-common v1 07/23] tests: sectionconfig: add case for opt. default prop requirde by all
Max R. Carrara
m.carrara at proxmox.com
Fri Dec 19 20:44:42 CET 2025
Add a PVE::SectionConfig test case for plugin systems that declare an
optional default property (in `private()->{propertyList}`) and mark it
as required on all child plugins.
In other words, all child plugins use the optional default property in
their `options()` methods, and do so with `optional => 0`.
In unified mode, such properties are 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 <m.carrara at proxmox.com>
---
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 f970d30..b49abfe 100755
--- a/test/SectionConfig/schema_comparison_test.pl
+++ b/test/SectionConfig/schema_comparison_test.pl
@@ -940,6 +940,210 @@ package OptionalCommonRequiredByOne {
}
}
+package OptionalCommonRequiredByAll {
+ use base qw(TestPackage);
+
+ sub desc($class) {
+ return
+ "in unified mode, optional default properties required by all plugins"
+ . " are required in createSchema and optional in updateSchema"
+ . " - in isolated mode, these properties are optional in *both* schemas";
+ }
+
+ package OptionalCommonRequiredByAll::PluginBase {
+ use base qw(PVE::SectionConfig);
+
+ my $DEFAULT_DATA = {
+ propertyList => {
+ common => {
+ type => 'string',
+ optional => 1,
+ },
+ },
+ };
+
+ sub private($class) {
+ return $DEFAULT_DATA;
+ }
+ };
+
+ package OptionalCommonRequiredByAll::PluginOne {
+ use base qw(OptionalCommonRequiredByAll::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 OptionalCommonRequiredByAll::PluginTwo {
+ use base qw(OptionalCommonRequiredByAll::PluginBase);
+
+ sub type($class) {
+ return 'two';
+ }
+
+ sub properties($class) {
+ return {
+ 'prop-two' => {
+ type => 'string',
+ optional => 1,
+ },
+ };
+ }
+
+ sub options($class) {
+ return {
+ common => {
+ optional => 0,
+ },
+ '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 => 1,
+ },
+ $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
More information about the pve-devel
mailing list