5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2024-12-22 21:33:47 +03:00

Add tests for verify_configid

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
This commit is contained in:
Dominic Jäger 2020-10-28 11:04:52 +01:00 committed by Thomas Lamprecht
parent a7886364a7
commit e37d592413
2 changed files with 28 additions and 1 deletions

View 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

27
test/format_test.pl Executable file
View File

@ -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();