From e37d592413ef7d1d143ffb43ce6284739722ca89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20J=C3=A4ger?= Date: Wed, 28 Oct 2020 11:04:52 +0100 Subject: [PATCH] Add tests for verify_configid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominic Jäger --- 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