-
Notifications
You must be signed in to change notification settings - Fork 10
/
address_test.go
58 lines (55 loc) · 1.32 KB
/
address_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
package socks5
import (
"net"
"testing"
)
var addressTests = []struct {
*Address
String string
Bytes []byte
}{
// ipv4
{
&Address{net.IPv4(127, 0, 0, 1).To4(), IPV4_ADDRESS, 1080},
"127.0.0.1:1080",
[]byte{0x01, 127, 0, 0, 1, 0x04, 0x38},
},
{
&Address{net.IPv4(172, 16, 1, 1).To4(), IPV4_ADDRESS, 1080},
"172.16.1.1:1080",
[]byte{0x01, 172, 16, 1, 1, 0x04, 0x38},
},
{
&Address{net.IPv4(192, 168, 1, 1).To4(), IPV4_ADDRESS, 1080},
"192.168.1.1:1080",
[]byte{0x01, 192, 168, 1, 1, 0x04, 0x38},
},
{
&Address{net.IPv4(0, 0, 0, 0).To4(), IPV4_ADDRESS, 1080},
"0.0.0.0:1080",
[]byte{0x01, 0, 0, 0, 0, 0x04, 0x38},
},
// ipv6
{
&Address{net.IPv6zero, IPV6_ADDRESS, 1080},
"[::]:1080",
[]byte{0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x38},
},
{&Address{net.IP{0x20, 0x01, 0x48, 0x60, 0, 0, 0x20, 0x01, 0, 0, 0, 0, 0, 0, 0x00, 0x68}, IPV6_ADDRESS, 1080},
"[2001:4860:0:2001::68]:1080",
[]byte{0x01, 0x20, 0x01, 0x48, 0x60, 0, 0, 0x20, 0x01, 0, 0, 0, 0, 0, 0, 0x00, 0x68, 0x04, 0x38},
},
// domain name
{
&Address{[]byte("localhost"), DOMAINNAME, 1080},
"localhost:1080",
[]byte{},
},
}
func TestAddress_String(t *testing.T) {
for _, a := range addressTests {
if a.Address.String() != a.String {
t.Errorf("get: %s, want: %s", a.Address.String(), a.String)
}
}
}