mirror of
https://git.proxmox.com/git/pve-guest-common
synced 2025-04-28 16:42:06 +00:00
tests: add map_expect_to_param_id feature for checking side-effects
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
e33cb61565
commit
975e60d986
@ -15,6 +15,9 @@ use PVE::AbstractConfig;
|
||||
# tests need to specify the method, the parameter and expected result
|
||||
# for neatly doing more tests per single method you can specifiy a subtests
|
||||
# array, which then only has params and expected result
|
||||
# sometimes the return value is less interesting to check than a parameter
|
||||
# reference, so one can use "map_expect_to_param_id" to tell the test system to
|
||||
# use that as expected result.
|
||||
|
||||
# note that the indentaion level below is "wrong" by design
|
||||
my $tests = [
|
||||
@ -133,6 +136,15 @@ sub do_test($$;$) {
|
||||
my ($params, $expect) = $test->@{qw(params expect)};
|
||||
|
||||
my $res = eval { PVE::AbstractConfig->$method(@$params) };
|
||||
|
||||
if (defined(my $param_id = $test->{map_expect_to_param_id})) {
|
||||
# it's a /cool/ hack, sometimes we have the interesting result in
|
||||
# "call-by-reference" param, and the return value is just some "I did
|
||||
# someting" or plain undef value. So allow to map the result to one of
|
||||
# the parameters
|
||||
$res = $params->[$param_id];
|
||||
}
|
||||
|
||||
if (my $err = $@) {
|
||||
is ($err, $expect, $name);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user