[pve-devel] [PATCH storage v5 11/12] test: get_subdir

Alwin Antreich a.antreich at proxmox.com
Tue Apr 28 15:58:24 CEST 2020


Co-Authored-by: Dominic Jaeger <d.jaeger at proxmox.com>
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 test/get_subdir_test.pm  | 44 ++++++++++++++++++++++++++++++++++++++++
 test/run_plugin_tests.pl |  1 +
 2 files changed, 45 insertions(+)
 create mode 100644 test/get_subdir_test.pm

diff --git a/test/get_subdir_test.pm b/test/get_subdir_test.pm
new file mode 100644
index 0000000..576c475
--- /dev/null
+++ b/test/get_subdir_test.pm
@@ -0,0 +1,44 @@
+package PVE::Storage::TestGetSubdir;
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+use PVE::Storage::Plugin;
+use Test::More;
+
+my $scfg_with_path = { path => '/some/path' };
+my $vtype_subdirs = PVE::Storage::Plugin::get_vtype_subdirs();
+
+# each test is comprised of the following array keys:
+# [0] => storage config; positive with path key
+# [1] => storage type;  see $vtype_subdirs
+# [2] => expected return from get_subdir
+my $tests = [
+    # failed matches
+    [ $scfg_with_path, 'none', "unknown vtype 'none'\n" ],
+    [ {}, 'iso', "storage definintion has no path\n" ],
+];
+
+# creates additional positive tests
+foreach my $type (keys %$vtype_subdirs) {
+    my $path = "$scfg_with_path->{path}/$vtype_subdirs->{$type}";
+    push @$tests, [ $scfg_with_path, $type, $path ];
+}
+
+plan tests => scalar @$tests;
+
+foreach my $tt (@$tests) {
+    my ($scfg, $type, $expected) = @$tt;
+
+    my $got;
+    eval { $got = PVE::Storage::Plugin->get_subdir($scfg, $type) };
+    $got = $@ if $@;
+
+    is ($got, $expected, "get_subdir for $type") || diag(explain($got));
+}
+
+done_testing();
+
+1;
diff --git a/test/run_plugin_tests.pl b/test/run_plugin_tests.pl
index 770b407..9e427eb 100755
--- a/test/run_plugin_tests.pl
+++ b/test/run_plugin_tests.pl
@@ -11,6 +11,7 @@ my $res = $harness->runtests(
     "parse_volname_test.pm",
     "list_volumes_test.pm",
     "path_to_volume_id_test.pm",
+    "get_subdir_test.pm",
 );
 
 exit -1 if !$res || $res->{failed} || $res->{parse_errors};
-- 
2.20.1





More information about the pve-devel mailing list