]> git.proxmox.com Git - pve-storage.git/blame - test/get_subdir_test.pm
config: add overrides for default directory locations
[pve-storage.git] / test / get_subdir_test.pm
CommitLineData
ddd313c9
AA
1package PVE::Storage::TestGetSubdir;
2
3use strict;
4use warnings;
5
6use lib qw(..);
7
8use PVE::Storage::Plugin;
9use Test::More;
10
11my $scfg_with_path = { path => '/some/path' };
12my $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
18my $tests = [
19 # failed matches
20 [ $scfg_with_path, 'none', "unknown vtype 'none'\n" ],
ffc31266 21 [ {}, 'iso', "storage definition has no path\n" ],
ddd313c9
AA
22];
23
24# creates additional positive tests
25foreach 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
3e7bd7da
LN
30# creates additional tests for overrides
31foreach my $type (keys %$vtype_subdirs) {
32 my $override = "/${type}_override";
33 my $scfg_with_override = { path => '/some/path', dirs => { $type => $override } };
34 push @$tests, [ $scfg_with_override, $type, "$scfg_with_override->{path}$scfg_with_override->{dirs}->{$type}" ];
35}
36
ddd313c9
AA
37plan tests => scalar @$tests;
38
39foreach my $tt (@$tests) {
40 my ($scfg, $type, $expected) = @$tt;
41
42 my $got;
43 eval { $got = PVE::Storage::Plugin->get_subdir($scfg, $type) };
44 $got = $@ if $@;
45
46 is ($got, $expected, "get_subdir for $type") || diag(explain($got));
47}
48
49done_testing();
50
511;