]>
git.proxmox.com Git - pve-common.git/blob - test/api_parameter_test.pl
2 package PVE
::TestAPIParameters
;
4 # Tests the automatic conversion of -list and array parameter types
16 use base
qw(PVE::RESTHandler);
20 name
=> 'list-format-with-list',
23 format
=> 'pve-configid-list',
26 'value-expected' => "foo,bar",
29 name
=> 'array-format-with-array',
34 format
=> 'pve-configid',
37 value
=> ['foo', 'bar'],
38 'value-expected' => ['foo', 'bar'],
40 # TODO: below behaviour should be deprecated with 9.x and fail with 10.x
42 name
=> 'list-format-with-alist',
45 format
=> 'pve-configid-list',
48 'value-expected' => "foo\0bar",
51 name
=> 'array-format-with-non-array',
56 format
=> 'pve-configid',
60 'value-expected' => ['foo'],
63 name
=> 'list-format-with-array',
66 format
=> 'pve-configid-list',
68 value
=> ['foo', 'bar'],
69 'value-expected' => "foo,bar",
73 for my $data ($setup->@*) {
74 __PACKAGE__-
>register_method({
75 name
=> $data->{name
},
76 path
=> $data->{name
},
79 additionalProperties
=> 0,
81 param
=> $data->{parameter
},
84 returns
=> { type
=> 'null' },
87 return $param->{param
};
91 my ($handler, $info) = __PACKAGE__-
>find_handler('POST', $data->{name
});
93 param
=> $data->{value
},
96 my $res = $handler->handle($info, $param);
97 is_deeply
($res, $data->{'value-expected'}, $data->{name
});