[pve-devel] [PATCH pve-common 1/3 v2] Add tests for verify_configid

Dominic Jäger d.jaeger at proxmox.com
Wed Oct 28 11:04:52 CET 2020


Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>
---
v1->v2: Didn't exist

 test/Makefile       |  2 +-
 test/format_test.pl | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100755 test/format_test.pl

diff --git a/test/Makefile b/test/Makefile
index b8118c7..85ecac5 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -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
index 0000000..3f225de
--- /dev/null
+++ b/test/format_test.pl
@@ -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
-- 
2.20.1





More information about the pve-devel mailing list