]>
git.proxmox.com Git - pve-common.git/blob - test/section_config_property_isolation_test.pl
11 use base
qw(PVE::SectionConfig);
15 type
=> { description
=> "Section type." },
19 format
=> 'pve-configid',
24 description
=> 'common value',
35 my ($class, $filename, $expected, $raw, $allow_unknown) = @_;
37 my $res = $class->parse_config($filename, $raw, $allow_unknown);
38 delete $res->{digest
};
40 is_deeply
($res, $expected, $filename);
42 my $written = $class->write_config($filename, $res, $allow_unknown);
43 my $res2 = $class->parse_config($filename, $written, $allow_unknown);
44 delete $res2->{digest
};
46 is_deeply
($res, $res2, "$filename - verify rewritten data");
50 my ($class, $filename, $expected, $raw) = @_;
52 eval { $class->parse_config($filename, $raw) };
53 die "test '$filename' succeeded unexpectedly\n" if !$@;
54 ok
(1, "$filename should fail to parse");
70 description
=> 'Field One',
76 description
=> 'Field Two',
82 description
=> 'Another field',
87 description
=> "Array Field with property string",
92 description
=> 'a property string',
96 description
=> 'first subfield'
111 common
=> { optional
=> 1 },
128 description
=> 'Field Two but different',
134 description
=> 'Another field',
139 description
=> "Array Field with property string",
143 description
=> 'a property string',
147 description
=> 'first subfield'
162 common
=> { optional
=> 1 },
173 Conf
::One-
>register();
174 Conf
::Two-
>register();
175 Conf-
>init(property_isolation
=> 1);
177 # FIXME: allow development debug warnings?!
178 local $SIG{__WARN__
} = sub { die @_; };
182 return { map { $_ => $n++ } @_ };
185 Conf-
>expect_success(
186 'property-isolation-test1',
194 arrayfield
=> [ 'subfield1=test' ],
201 another
=> 'more-text',
206 another
=> 'even more text',
209 order
=> { t1
=> 1, t2
=> 2, t3
=> 3 },
216 arrayfield subfield1=test
226 another even more text
229 my $with_unknown_data = {
242 another
=> 'more-text',
247 another
=> 'even more text',
249 'subfield1=test,subfield2=2',
256 unknownfield
=> 'shouldnotbehere',
257 unknownarray
=> ['entry1', 'entry2'],
260 order
=> enum
(qw(t1 t2 invalid t3)),
262 my $with_unknown_text = <<"EOF";
276 unknownfield shouldnotbehere
282 another even more text
283 arrayfield subfield1=test,subfield2=2
284 arrayfield subfield1=test2
287 my $wrong_field_schema_data = {
293 field2
=> 5, # this should fail
296 order
=> enum
(qw(t1)),
299 my $wrong_field_schema_text = <<"EOF";
306 Conf-
>expect_fail('property-isolation-wrong-field-schema', $wrong_field_schema_data, $wrong_field_schema_text);
307 Conf-
>expect_fail('property-isolation-unknown-forbidden', $with_unknown_data, $with_unknown_text);
308 Conf-
>expect_success('property-isolation-unknown-allowed', $with_unknown_data, $with_unknown_text, 1);
311 my $create_schema = Conf-
>createSchema();
312 my $expected_create_schema = {
313 additionalProperties
=> 0,
319 format
=> 'pve-configid',
323 description
=> 'Section type.',
324 enum
=> [ 'one', 'two' ],
331 description
=> 'common value'
335 'type-property' => 'type',
336 'instance-types' => [ 'one' ],
340 description
=> 'Field One'
345 description
=> 'Field Two',
348 'instance-types' => [ 'one' ],
355 description
=> 'Field Two but different',
357 'instance-types' => [ 'two' ],
361 'type-property' => 'type'
368 description
=> 'first subfield',
377 description
=> 'a property string'
379 description
=> 'Array Field with property string',
386 description
=> 'Another field'
391 is_deeply
($create_schema, $expected_create_schema, "property-isolation create schema test");
393 my $update_schema = Conf-
>updateSchema();
394 my $expected_update_schema = {
395 additionalProperties
=> 0,
401 format
=> 'pve-configid',
406 enum
=> [ 'one', 'two' ],
407 description
=> 'Section type.'
412 description
=> 'Prevent changes if current configuration file has a different digest. This can be used to prevent concurrent modifications.',
416 description
=> 'A list of settings you want to delete.',
418 format
=> 'pve-configid-list',
424 description
=> 'common value',
429 description
=> 'Field One',
431 'instance-types' => [ 'one' ],
432 'type-property' => 'type',
438 'type-property' => 'type',
445 'instance-types' => [ 'one' ],
446 description
=> 'Field Two'
449 description
=> 'Field Two but different',
451 'instance-types' => [ 'two' ],
462 description
=> 'a property string',
471 description
=> 'first subfield',
476 description
=> 'Array Field with property string'
479 description
=> 'Another field',
485 is_deeply
($update_schema, $expected_update_schema, "property-isolation update schema test");