]> git.proxmox.com Git - pve-guest-common.git/commitdiff
tests: add map_expect_to_param_id feature for checking side-effects
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 18:28:59 +0000 (20:28 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 18:28:59 +0000 (20:28 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
tests/abstract-config-tests.pl

index d807623fc7e3f1c70a34785397bec27456f2a57c..8f58e42aa02a2c1016bcb5b55900612e2abd6a8f 100755 (executable)
@@ -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 {