-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
45 lines (42 loc) · 957 Bytes
/
utils_test.go
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
package ddio
import (
"net"
"reflect"
"strconv"
"testing"
)
func TestProtocolParse(t *testing.T) {
t.Run("IP_V4", func(t *testing.T) {
addr := "tcp://127.0.0.1:8080?level=2"
cmpAddr := NetPollConfig{
Protocol: TCP_V4,
IP: net.ParseIP("127.0.0.1"),
Port: 8080,
}
testFn(t, addr, cmpAddr, 2)
})
t.Run("IP_V6", func(t *testing.T) {
addr := "tcp://fe80::1029:f994:b74a:7bef:8099?level=10"
cmpAddr := NetPollConfig{
Protocol: TCP_V6,
IP: net.ParseIP("fe80::1029:f994:b74a:7bef"),
Port: 8099,
}
testFn(t, addr, cmpAddr, 10)
})
}
func testFn(t *testing.T, addr string, cmpAddr NetPollConfig, cmpLevel int) {
parseAddr, argMap, err := parseAddress(addr)
if err != nil {
t.Error(err)
return
}
if level, _ := strconv.Atoi(argMap["level"]); level != cmpLevel {
t.Error("level not equal")
return
}
if !reflect.DeepEqual(parseAddr, cmpAddr) {
t.Error("parse addr not equal")
return
}
}