-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve_test.go
84 lines (82 loc) · 1.68 KB
/
resolve_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
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
78
79
80
81
82
83
84
package mcproto
import "testing"
func Test_splitHostPort(t *testing.T) {
tests := []struct {
name string
address string
wantHost string
wantPort string
}{
{
name: "ipv4",
address: "127.0.0.1",
wantHost: "127.0.0.1",
wantPort: "",
},
{
name: "ipv4_port",
address: "127.0.0.1:25565",
wantHost: "127.0.0.1",
wantPort: "25565",
},
{
name: "host_short",
address: "localhost",
wantHost: "localhost",
wantPort: "",
},
{
name: "host_short_port",
address: "localhost:25565",
wantHost: "localhost",
wantPort: "25565",
},
{
name: "host",
address: "mc.raqb.it",
wantHost: "mc.raqb.it",
wantPort: "",
},
{
name: "host_port",
address: "mc.raqb.it:25565",
wantHost: "mc.raqb.it",
wantPort: "25565",
},
{
name: "ipv6_short",
address: "::1",
wantHost: "::1",
wantPort: "",
},
{
name: "ipv6_short_port",
address: "[::1]:25565",
wantHost: "::1",
wantPort: "25565",
},
{
name: "ipv6",
address: "c0ec:5d71:7830:511d:ae76:dbf0:d659:9754",
wantHost: "c0ec:5d71:7830:511d:ae76:dbf0:d659:9754",
wantPort: "",
},
{
name: "ipv6_port",
address: "[c0ec:5d71:7830:511d:ae76:dbf0:d659:9754]:25565",
wantHost: "c0ec:5d71:7830:511d:ae76:dbf0:d659:9754",
wantPort: "25565",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHost, gotPort := splitHostPort(tt.address)
if gotHost != tt.wantHost {
t.Errorf("splitHostPort() gotHost = %v, want %v", gotHost, tt.wantHost)
}
if gotPort != tt.wantPort {
t.Errorf("splitHostPort() gotPort = %v, want %v", gotPort, tt.wantPort)
}
})
}
}