[pve-devel] [PATCH pve-common v1 16/23] tests: sectionconfig: add case for differing req. default prop uses
Max R. Carrara
m.carrara at proxmox.com
Fri Dec 19 20:44:51 CET 2025
Add a PVE::SectionConfig isolated mode test case where a required
default property (i.e. it's defined in `private()->{propertyList}`) is
marked as required by one plugin, but as optional by the other.
In the create schema, such a property uses a `oneOf` schema to differ
between the cases of both plugins. In other words, if a plugin marked
it as optional, it is marked as optional in the create schema too, and
vice versa.
In the update schema, such a property is marked as optional for both
plugins.
Signed-off-by: Max R. Carrara <m.carrara at proxmox.com>
---
test/SectionConfig/schema_isolated_test.pl | 168 +++++++++++++++++++++
1 file changed, 168 insertions(+)
diff --git a/test/SectionConfig/schema_isolated_test.pl b/test/SectionConfig/schema_isolated_test.pl
index 202e039..95980de 100755
--- a/test/SectionConfig/schema_isolated_test.pl
+++ b/test/SectionConfig/schema_isolated_test.pl
@@ -591,6 +591,174 @@ package OptionalCommonRequiredAndOptional {
}
}
+package RequiredCommonRequiredAndOptional {
+ use base qw(TestPackage);
+
+ sub desc($class) {
+ return "when a required default property is marked as both optional and required"
+ . " by different plugins, 'oneOf' is used in createSchema";
+ }
+
+ package RequiredCommonRequiredAndOptional::PluginBase {
+ use base qw(PVE::SectionConfig);
+
+ my $DEFAULT_DATA = {
+ propertyList => {
+ common => {
+ type => 'string',
+ optional => 0,
+ },
+ },
+ };
+
+ sub private($class) {
+ return $DEFAULT_DATA;
+ }
+ };
+
+ package RequiredCommonRequiredAndOptional::PluginOne {
+ use base qw(RequiredCommonRequiredAndOptional::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 RequiredCommonRequiredAndOptional::PluginTwo {
+ use base qw(RequiredCommonRequiredAndOptional::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' => {
+ oneOf => [
+ {
+ 'instance-types' => [
+ "one",
+ ],
+ optional => 0,
+ type => 'string',
+ },
+ {
+ 'instance-types' => [
+ "two",
+ ],
+ optional => 1,
+ type => 'string',
+ },
+ ],
+ 'type-property' => 'type',
+ },
+ },
+ };
+ }
+
+ 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