]>
git.proxmox.com Git - pve-guest-common.git/blob - tests/abstract-config-tests.pl
11 use PVE
::AbstractConfig
;
14 # tests for different top level method implementations of AbstractConfig
15 # tests need to specify the method, the parameter and expected result
16 # for neatly doing more tests per single method you can specifiy a subtests
17 # array, which then only has params and expected result
19 # note that the indentaion level below is "wrong" by design
22 method => 'parse_pending_delete',
25 params
=> [ "memory,cpu" ],
27 cpu
=> { force
=> 0, },
28 memory
=> { force
=> 0, },
32 params
=> [ "memory;cpu,!mp0" ],
34 cpu
=> { force
=> 0, },
35 memory
=> { force
=> 0, },
36 mp0
=> { force
=> 1, },
40 params
=> [ " memory ; cpu, !mp0, !mp1" ],
41 expect
=> { # can separate with comma, semicolon, spaces
42 cpu
=> { force
=> 0, },
43 memory
=> { force
=> 0, },
44 mp0
=> { force
=> 1, },
45 mp1
=> { force
=> 1, },
49 params
=> [ "!!memory" ],
50 expect
=> { # we have no double negation, only simple stuff
51 '!memory' => { force
=> 1, },
55 params
=> [ " mem ory" ],
56 expect
=> { # we do not support keys with spaces, seens as two different ones
57 'mem' => { force
=> 0, },
58 'ory' => { force
=> 0, },
64 method => 'print_pending_delete',
68 cpu
=> { force
=> 0, },
69 memory
=> { force
=> 0, },
71 expect
=> "memory,cpu",
74 params
=> [{ # we have no double negation, only simple stuff
75 '!memory' => { force
=> 1, },
81 ]; # tests definition end
85 my ($method, $test, $name) = @_;
87 fail
("incomplete test, params or expected missing")
88 if !exists $test->{params
} || !exists $test->{expect
};
90 my ($params, $expect) = $test->@{qw(params expect)};
92 my $res = eval { PVE
::AbstractConfig-
>$method(@$params) };
94 is ($err, $expect, $name);
96 is_deeply
($res, $expect, $name);
100 for my $test (@$tests) {
101 my $method = $test->{method} or fail
("missing AbstractConfig method to test") and next;
103 my $name = $test->{name
} // $method;
105 if (defined(my $subtests = $test->{subtests
})) {
106 subtest
$name => sub {
107 for my $subtest (@$subtests) {
108 do_test
($method, $subtest);
112 do_test
($method, $test, $name);
114 #my $expected = $test->{expect};