-
Notifications
You must be signed in to change notification settings - Fork 0
/
addr_test.go
37 lines (30 loc) · 1004 Bytes
/
addr_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
package main
import (
"testing"
)
func equalSlice(t *testing.T, expected, actual []string) {
if len(expected) != len(actual) {
t.Error("mismatching slice lengths")
}
for i := range expected {
if expected[i] != actual[i] {
t.Errorf("mismatching index %d, expected %s got %s", i, expected[i], actual[i])
}
}
}
func TestSplitHost(t *testing.T) {
t.Run("empty string", func(t *testing.T) {
p := SplitHostPort("")
equalSlice(t, []string{""}, p)
})
t.Run("ipv4 addr", func(t *testing.T) {
p := SplitHostPort(":2222:[tcp.echo.server@srv-127.0.0.1:53]:0")
equalSlice(t, []string{"", "2222", "tcp.echo.server@srv-127.0.0.1:53", "0"}, p)
p = SplitHostPort(":2222:[tcp.echo.server@srv-[127.0.0.1]:53]:0")
equalSlice(t, []string{"", "2222", "tcp.echo.server@srv-[127.0.0.1]:53", "0"}, p)
})
t.Run("ipv6 addr", func(t *testing.T) {
p := SplitHostPort(":2222:[tcp.echo.server@srv-[::1]:53]:0")
equalSlice(t, []string{"", "2222", "tcp.echo.server@srv-[::1]:53", "0"}, p)
})
}