]> git.gsnw.org Git - fping.git/commitdiff
Fix JSON output print_per_system_stats_json dash to null
authorGerman Service Network <support@gsnw.de>
Wed, 30 Apr 2025 16:39:15 +0000 (18:39 +0200)
committerSebastian <176771227+gsnw-sebast@users.noreply.github.com>
Sat, 12 Jul 2025 05:43:18 +0000 (07:43 +0200)
ci/test-16-json-output.pl
src/fping.c

index f1cd5ba414ceb1cb2ac36944c24dd61e36030ffc..1fd21913ad0beef0a6842fdc4793737bc0192f11 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::Command tests => 48;
+use Test::Command tests => 54;
 use Test::More;
 
 # fping -J -c 2 127.0.0.1
@@ -79,6 +79,24 @@ $cmd->stdout_like(qr/^\{"summary":\s\{"host":\s"127\.0\.0\.1",\s"xmt":\s\d+,\s"r
 $cmd->stderr_is_eq("");
 }
 
+# fping -J -C 1 127.0.0.1
+{
+my $cmd = Test::Command->new(cmd => "fping -J -C 1 127.0.0.1");
+$cmd->exit_is_num(0);
+$cmd->stdout_like(qr/^\{"resp":\s\{"host":\s"127\.0\.0\.1",\s"seq":\s\d+,\s"size":\s\d+,\s"rtt":\s\d+.\d+,\s"rttAvg":\s\d+.\d+,\s"loss":\s\d+\}\}
+\{"vSum":\s\{"host":\s"127\.0\.0\.1",\s"values":\s\[\d+.\d+\]\}\}?$/);
+$cmd->stderr_is_eq("");
+}
+
+# fping -J -C 1 192.0.2.47
+{
+my $cmd = Test::Command->new(cmd => "fping -J -C 1 192.0.2.47");
+$cmd->exit_is_num(1);
+$cmd->stdout_like(qr/^\{"timeout":\s\{"host":\s"192\.0\.2\.47",\s"seq":\s\d+,\s"rttAvg":\s"NaN",\s"loss":\s\d+\}\}
+\{"vSum":\s\{"host":\s"192\.0\.2\.47",\s"values":\s\[null\]\}\}?$/);
+$cmd->stderr_is_eq("");
+}
+
 # fping -J -C 1 -q 127.0.0.1
 {
 my $cmd = Test::Command->new(cmd => "fping -J -C 1 -q 127.0.0.1");
index c632fb089aafbdb8e6f08e5864597322a9573834..4595fa82ea3ece5543b99162c8a1b904c2b07f5d 100644 (file)
@@ -2123,7 +2123,7 @@ void print_per_system_stats_json(void)
                 if ((resp = h->resp_times[j]) >= 0)
                     fprintf(stdout, "%s", sprint_tm(resp));
                 else
-                    fprintf(stdout, "-");
+                    fprintf(stdout, "null");
             }
 
             fprintf(stdout, "]}");