2017-10-23 17:47:20 -04:00
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"v2ray.com/core/common/net"
|
|
|
|
"v2ray.com/ext/assert"
|
|
|
|
)
|
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
var IsIPv4 = assert.CreateMatcher(func(a net.Address) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a.Family().IsIPv4()
|
2017-10-24 10:15:35 -04:00
|
|
|
}, "is IPv4")
|
2017-10-23 17:47:20 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
var IsIPv6 = assert.CreateMatcher(func(a net.Address) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a.Family().IsIPv6()
|
2017-10-24 10:15:35 -04:00
|
|
|
}, "is IPv6")
|
2017-10-23 17:47:20 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
var IsIP = assert.CreateMatcher(func(a net.Address) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a.Family().IsIPv4() || a.Family().IsIPv6()
|
2017-10-24 10:15:35 -04:00
|
|
|
}, "is IP")
|
2017-10-23 17:47:20 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
var IsTCP = assert.CreateMatcher(func(a net.Destination) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a.Network == net.Network_TCP
|
2017-10-24 10:15:35 -04:00
|
|
|
}, "is TCP")
|
2017-10-23 17:47:20 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
var IsUDP = assert.CreateMatcher(func(a net.Destination) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a.Network == net.Network_UDP
|
2017-10-24 10:15:35 -04:00
|
|
|
}, "is UDP")
|
2017-10-23 17:47:20 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
var IsDomain = assert.CreateMatcher(func(a net.Address) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a.Family().IsDomain()
|
2017-10-24 10:15:35 -04:00
|
|
|
}, "is Domain")
|
2017-10-23 17:47:20 -04:00
|
|
|
|
|
|
|
func init() {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert.RegisterEqualsMatcher(func(a, b net.Address) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a == b
|
2017-10-24 10:15:35 -04:00
|
|
|
})
|
2017-10-23 17:47:20 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert.RegisterEqualsMatcher(func(a, b net.Destination) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a == b
|
2017-10-24 10:15:35 -04:00
|
|
|
})
|
2017-10-23 17:47:20 -04:00
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert.RegisterEqualsMatcher(func(a, b net.Port) bool {
|
2017-10-23 17:47:20 -04:00
|
|
|
return a == b
|
2017-10-24 10:15:35 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
assert.RegisterEqualsMatcher(func(a, b net.IP) bool {
|
|
|
|
return a.Equal(b)
|
|
|
|
})
|
2017-10-23 17:47:20 -04:00
|
|
|
}
|