Skip to content

Commit

Permalink
add JSON output test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Bonk committed Nov 22, 2019
1 parent b871e4d commit 3923fa5
Showing 1 changed file with 135 additions and 0 deletions.
135 changes: 135 additions & 0 deletions ci/test-16-json.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/perl -w

use Test::Command;
use Test::More;

plan tests => 18;

# summary
{
my $cmd = Test::Command->new(cmd => "fping -c 2 -J 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\{
"hosts": \{
"127\.0\.0\.1": \{
"xmt": 2,
"rcv": 2,
"loss_percentage": 0,
"min": \d.\d+,
"avg": \d.\d+,
"max": \d.\d+
\}
\}
\}}
);
$cmd->stderr_is_eq("");
}

# all RTTs
{
my $cmd = Test::Command->new(cmd => "fping -C 2 -J 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\{
"hosts": \{
"127\.0\.0\.1": \[
\d.\d+,
\d.\d+
\]
\}
\}}
);
$cmd->stderr_is_eq("");
}

# summary with stats and outage
{
my $cmd = Test::Command->new(cmd => "fping -c 2 -s -o -J 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\{
"hosts": \{
"127\.0\.0\.1": \{
"xmt": 2,
"rcv": 2,
"loss_percentage": 0,
"outage": 0,
"min": \d.\d+,
"avg": \d.\d+,
"max": \d.\d+
\}
\},
"stats": \{
"targets": 1,
"alive": 1,
"unreachable": 0,
"unknown_addresses": 0,
"timeouts": 0,
"icmp_echos_sent": 2,
"icmp_echo_replies_received": 2,
"other_icmp_received": 0,
"min_rtt": \d.\d+,
"avg_rtt": \d.\d+,
"max_rtt": \d.\d+,
"elapsed_real_time": \d.\d+
\}
\}}
);
$cmd->stderr_is_eq("");
}

# all RTTs with stats
{
my $cmd = Test::Command->new(cmd => "fping -C 2 -s -J 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\{
"hosts": \{
"127\.0\.0\.1": \[
\d.\d+,
\d.\d+
\]
\},
"stats": \{
"targets": 1,
"alive": 1,
"unreachable": 0,
"unknown_addresses": 0,
"timeouts": 0,
"icmp_echos_sent": 2,
"icmp_echo_replies_received": 2,
"other_icmp_received": 0,
"min_rtt": \d.\d+,
"avg_rtt": \d.\d+,
"max_rtt": \d.\d+,
"elapsed_real_time": \d.\d+
\}
\}}
);
$cmd->stderr_is_eq("");
}

# more indentation
{
my $cmd = Test::Command->new(cmd => "fping -c 2 --json=4 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\{
"hosts": \{
"127\.0\.0\.1": \{
"xmt": 2,
"rcv": 2,
"loss_percentage": 0,
"min": \d.\d+,
"avg": \d.\d+,
"max": \d.\d+
\}
\}
\}}
);
$cmd->stderr_is_eq("");
}

# no pretty-print
{
my $cmd = Test::Command->new(cmd => "fping -c 2 --json=0 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\{"hosts":\{"127\.0\.0\.1":\{"xmt":2,"rcv":2,"loss_percentage":0,"min":\d.\d+,"avg":\d.\d+,"max":\d.\d+\}\}\}});
$cmd->stderr_is_eq("");
}

0 comments on commit 3923fa5

Please sign in to comment.