From: Eric Bollengier Date: Wed, 31 Mar 2021 15:28:43 +0000 (+0200) Subject: regress: Add function to test json string in bperl X-Git-Tag: Release-11.3.2~647 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2268f8e0ac2c287f42f51c4df95b8cf766411232;p=thirdparty%2Fbacula.git regress: Add function to test json string in bperl --- diff --git a/regress/scripts/functions.pm b/regress/scripts/functions.pm index 291277b6d..790b6a6fd 100644 --- a/regress/scripts/functions.pm +++ b/regress/scripts/functions.pm @@ -52,7 +52,7 @@ our @EXPORT = qw(update_some_files create_many_files check_multiple_copies check_openfile check_cloud_hash check_bscan add_log_message compare_backup_content check_tls_traces println add_virtual_changer check_events check_events_json create_many_hardlinks check_dot_status parse_fuse_trace generate_random_seek - check_storage_selection + check_storage_selection check_json ); @@ -2551,4 +2551,28 @@ sub check_storage_selection exit $err; } +# We validate a json string +sub check_json +{ + my ($file) = @_; + open(FP, $file) or die "ERROR: Unable to open $file"; + my $content = join("", ); + close(FP); + + my $test_json; + eval 'use JSON qw/decode_json/; $test_json = JSON->new;'; + if ($@) { + print "INFO: JSON validation is disabled ERR=$@\n"; + exit 1; + } + + eval { + my $var = $test_json->decode($content); + }; + if ($@) { + print "ERROR: Unable to decode json data. ERR=$@\n"; + exit 1; + } + exit 0; +} 1;