1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package netstack
import (
"net/netip"
"testing"
)
func TestWindowsPingOutputIsSuccess(t *testing.T) {
tests := []struct {
name string
ip string
out string
want bool
}{
{
name: "success",
ip: "10.0.0.1",
want: true,
out: `Pinging 10.0.0.1 with 32 bytes of data:
Reply from 10.0.0.1: bytes=32 time=7ms TTL=64
Ping statistics for 10.0.0.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 7ms, Maximum = 7ms, Average = 7ms
`,
},
{
name: "success_sub_millisecond",
ip: "10.0.0.1",
want: true,
out: `Pinging 10.0.0.1 with 32 bytes of data:
Reply from 10.0.0.1: bytes=32 time<1ms TTL=64
Ping statistics for 10.0.0.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 7ms, Maximum = 7ms, Average = 7ms
`,
},
{
name: "success_german",
ip: "10.0.0.1",
want: true,
out: `Ping wird ausgeführt für 10.0.0.1 mit 32 Bytes Daten:
Antwort von from 10.0.0.1: Bytes=32 Zeit=7ms TTL=64
Ping-Statistik für 10.0.0.1:
Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0 (0% Verlust),
Ca. Zeitangaben in Millisek.:
Minimum = 7ms, Maximum = 7ms, Mittelwert = 7ms
`,
},
{
name: "unreachable",
ip: "10.0.0.6",
want: false,
out: `Pinging 10.0.0.6 with 32 bytes of data:
Reply from 10.0.108.189: Destination host unreachable
Ping statistics for 10.0.0.6:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := windowsPingOutputIsSuccess(netip.MustParseAddr(tt.ip), []byte(tt.out))
if got != tt.want {
t.Errorf("got %v; want %v", got, tt.want)
}
})
}
}
|