]> git.proxmox.com Git - pve-common.git/commitdiff
Add tests for verify_configid
authorDominic Jäger <d.jaeger@proxmox.com>
Wed, 28 Oct 2020 10:04:52 +0000 (11:04 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 29 Oct 2020 14:20:40 +0000 (15:20 +0100)
Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
test/Makefile
test/format_test.pl [new file with mode: 0755]

index b8118c7f3162d2a626a14305078055ee594c5318..85ecac5fb9ec890bce16b18d1c0c260e25ef4cd7 100644 (file)
@@ -6,7 +6,7 @@ all:
 
 export PERLLIB=../src
 
-check: lock_file.test calendar_event_test.test convert_size_test.test procfs_tests.test
+check: lock_file.test calendar_event_test.test convert_size_test.test procfs_tests.test format_test.test
        for d in $(SUBDIRS); do $(MAKE) -C $$d check; done
 
 %.test: %.pl
diff --git a/test/format_test.pl b/test/format_test.pl
new file mode 100755 (executable)
index 0000000..3f225de
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib '../src';
+use PVE::JSONSchema;
+
+use Test::More;
+use Test::MockModule;
+
+my $valid_configids = [
+       'aa', 'a0', 'a_', 'a-', 'a-a', 'a'x100, 'Aa', 'AA',
+];
+my $invalid_configids = [
+       'a', 'a+', '1a', '_a', '-a', '+a', 'A',
+];
+
+my $noerr = 1; # easier to test
+foreach my $id (@$valid_configids) {
+    is(PVE::JSONSchema::pve_verify_configid($id, $noerr), $id, 'valid configid');
+}
+foreach my $id (@$invalid_configids) {
+    is(PVE::JSONSchema::pve_verify_configid($id, $noerr), undef, 'invalid configid');
+}
+
+done_testing();
\ No newline at end of file