]>
git.proxmox.com Git - pve-common.git/blob - test/section_config_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
=> 'Another field',
84 common
=> { optional
=> 1 },
86 another
=> { optional
=> 1 },
103 description
=> 'Field Two',
109 description
=> "Array Field with property string",
113 description
=> 'a property string',
117 description
=> 'first subfield'
132 common
=> { optional
=> 1 },
135 arrayfield
=> { optional
=> 1 },
147 Conf
::One-
>register();
148 Conf
::Two-
>register();
151 # FIXME: allow development debug warnings?!
152 local $SIG{__WARN__
} = sub { die @_; };
156 return { map { $_ => $n++ } @_ };
159 Conf-
>expect_success(
172 another
=> 'more-text',
177 another
=> 'even more text',
180 order
=> { t1
=> 1, t2
=> 2, t3
=> 3 },
194 another even more text
197 my $with_unknown_data = {
208 another
=> 'more-text',
213 another
=> 'even more text',
215 'subfield1=test,subfield2=2',
222 unknownfield
=> 'shouldnotbehere',
223 unknownarray
=> ['entry1', 'entry2'],
226 order
=> enum
(qw(t1 t2 invalid t3)),
228 my $with_unknown_text = <<"EOF";
240 unknownfield shouldnotbehere
246 another even more text
247 arrayfield subfield1=test,subfield2=2
248 arrayfield subfield1=test2
251 Conf-
>expect_fail('unknown-forbidden', $with_unknown_data, $with_unknown_text);
252 Conf-
>expect_success('unknown-allowed', $with_unknown_data, $with_unknown_text, 1);
255 my $create_schema = Conf-
>createSchema();
256 my $expected_create_schema = {
257 additionalProperties
=> 0,
262 format
=> 'pve-configid',
267 description
=> 'Section type.',
268 enum
=> ['one', 'two'],
273 description
=> 'common value',
277 description
=> 'Field One',
285 'description'=> 'Field Two',
292 'description'=> 'Array Field with property string',
294 'description'=> 'a property string',
302 'description'=> 'first subfield',
312 'description'=> 'Another field',
319 is_deeply
($create_schema, $expected_create_schema, "create schema test");
321 my $update_schema = Conf-
>updateSchema();
322 my $expected_update_schema = {
323 additionalProperties
=> 0,
328 format
=> 'pve-configid',
333 type
=> 'string', format
=> 'pve-configid-list',
334 description
=> "A list of settings you want to delete.",
338 digest
=> PVE
::JSONSchema
::get_standard_option
('pve-config-digest'),
340 description
=> 'common value',
345 description
=> 'Field One',
352 description
=> 'Field Two',
359 description
=> 'Array Field with property string',
362 description
=> 'a property string',
370 description
=> 'first subfield',
379 description
=> 'Another field',
385 is_deeply
($update_schema, $expected_update_schema, "update schema test");