mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
fix: ipv6网络测试不通
This commit is contained in:
62
server/task_test.go
Normal file
62
server/task_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var testTargets = []struct {
|
||||
target string
|
||||
}{
|
||||
{"v6-sh-cm.oojj.de"},
|
||||
{"2409:8c1e:8f80:2:6a::"},
|
||||
{"[2409:8c1e:8f80:2:6a::]:80"},
|
||||
{"v4-sh-cm.oojj.de"},
|
||||
{"117.185.125.154"},
|
||||
{"117.185.125.154:80"},
|
||||
}
|
||||
|
||||
func TestICMPPing(t *testing.T) {
|
||||
timeout := 3 * time.Second
|
||||
for _, tt := range testTargets {
|
||||
t.Run(tt.target, func(t *testing.T) {
|
||||
latency, err := icmpPing(tt.target, timeout)
|
||||
if latency < -1 {
|
||||
t.Errorf("ICMP ping %s: invalid latency %d", tt.target, latency)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("ICMP ping %s error: %v", tt.target, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTCPPing(t *testing.T) {
|
||||
timeout := 3 * time.Second
|
||||
for _, tt := range testTargets {
|
||||
t.Run(tt.target, func(t *testing.T) {
|
||||
latency, err := tcpPing(tt.target, timeout)
|
||||
if latency < -1 {
|
||||
t.Errorf("TCP ping %s: invalid latency %d", tt.target, latency)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("TCP ping %s error: %v", tt.target, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPPing(t *testing.T) {
|
||||
timeout := 3 * time.Second
|
||||
for _, tt := range testTargets {
|
||||
t.Run(tt.target, func(t *testing.T) {
|
||||
latency, err := httpPing(tt.target, timeout)
|
||||
if latency < -1 {
|
||||
t.Errorf("HTTP ping %s: invalid latency %d", tt.target, latency)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("HTTP ping %s error: %v", tt.target, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user