Fix Go agent packet loss parsing
This commit is contained in:
@@ -47,3 +47,34 @@ func TestLooksLikeMAC(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePacketLossBusyBox(t *testing.T) {
|
||||
output := `PING 10.10.10.10 (10.10.10.10): 56 data bytes
|
||||
64 bytes from 10.10.10.10: seq=0 ttl=64 time=1.157 ms
|
||||
64 bytes from 10.10.10.10: seq=1 ttl=64 time=0.883 ms
|
||||
64 bytes from 10.10.10.10: seq=2 ttl=64 time=0.952 ms
|
||||
|
||||
--- 10.10.10.10 ping statistics ---
|
||||
3 packets transmitted, 3 packets received, 0% packet loss
|
||||
round-trip min/avg/max = 0.883/0.997/1.157 ms`
|
||||
|
||||
if loss := parsePacketLoss(output); loss != 0 {
|
||||
t.Fatalf("expected 0%% packet loss, got %v", loss)
|
||||
}
|
||||
if latency := parseLatency(output); latency != 0.997 {
|
||||
t.Fatalf("expected avg latency 0.997, got %v", latency)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePacketLossGNU(t *testing.T) {
|
||||
output := `--- 1.1.1.1 ping statistics ---
|
||||
3 packets transmitted, 2 received, 33.3333% packet loss, time 2002ms
|
||||
rtt min/avg/max/mdev = 10.100/11.200/12.300/0.100 ms`
|
||||
|
||||
if loss := parsePacketLoss(output); loss != 33.3333 {
|
||||
t.Fatalf("expected 33.3333%% packet loss, got %v", loss)
|
||||
}
|
||||
if latency := parseLatency(output); latency != 11.2 {
|
||||
t.Fatalf("expected avg latency 11.2, got %v", latency)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user