-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.go
48 lines (37 loc) · 1.07 KB
/
assert.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
package testing
import (
"v2ray.com/core/common/net"
"v2ray.com/ext/assert"
)
var IsIPv4 = assert.CreateMatcher(func(a net.Address) bool {
return a.Family().IsIPv4()
}, "is IPv4")
var IsIPv6 = assert.CreateMatcher(func(a net.Address) bool {
return a.Family().IsIPv6()
}, "is IPv6")
var IsIP = assert.CreateMatcher(func(a net.Address) bool {
return a.Family().IsIPv4() || a.Family().IsIPv6()
}, "is IP")
var IsTCP = assert.CreateMatcher(func(a net.Destination) bool {
return a.Network == net.Network_TCP
}, "is TCP")
var IsUDP = assert.CreateMatcher(func(a net.Destination) bool {
return a.Network == net.Network_UDP
}, "is UDP")
var IsDomain = assert.CreateMatcher(func(a net.Address) bool {
return a.Family().IsDomain()
}, "is Domain")
func init() {
assert.RegisterEqualsMatcher(func(a, b net.Address) bool {
return a == b
})
assert.RegisterEqualsMatcher(func(a, b net.Destination) bool {
return a == b
})
assert.RegisterEqualsMatcher(func(a, b net.Port) bool {
return a == b
})
assert.RegisterEqualsMatcher(func(a, b net.IP) bool {
return a.Equal(b)
})
}