]>
Commit | Line | Data |
---|---|---|
ddd313c9 AA |
1 | package PVE::Storage::TestGetSubdir; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use lib qw(..); | |
7 | ||
8 | use PVE::Storage::Plugin; | |
9 | use Test::More; | |
10 | ||
11 | my $scfg_with_path = { path => '/some/path' }; | |
12 | my $vtype_subdirs = PVE::Storage::Plugin::get_vtype_subdirs(); | |
13 | ||
14 | # each test is comprised of the following array keys: | |
15 | # [0] => storage config; positive with path key | |
16 | # [1] => storage type; see $vtype_subdirs | |
17 | # [2] => expected return from get_subdir | |
18 | my $tests = [ | |
19 | # failed matches | |
20 | [ $scfg_with_path, 'none', "unknown vtype 'none'\n" ], | |
21 | [ {}, 'iso', "storage definintion has no path\n" ], | |
22 | ]; | |
23 | ||
24 | # creates additional positive tests | |
25 | foreach my $type (keys %$vtype_subdirs) { | |
26 | my $path = "$scfg_with_path->{path}/$vtype_subdirs->{$type}"; | |
27 | push @$tests, [ $scfg_with_path, $type, $path ]; | |
28 | } | |
29 | ||
30 | plan tests => scalar @$tests; | |
31 | ||
32 | foreach my $tt (@$tests) { | |
33 | my ($scfg, $type, $expected) = @$tt; | |
34 | ||
35 | my $got; | |
36 | eval { $got = PVE::Storage::Plugin->get_subdir($scfg, $type) }; | |
37 | $got = $@ if $@; | |
38 | ||
39 | is ($got, $expected, "get_subdir for $type") || diag(explain($got)); | |
40 | } | |
41 | ||
42 | done_testing(); | |
43 | ||
44 | 1; |