v2ray-core/common/net/testing/assert.go

49 lines
1.1 KiB
Go
Raw Normal View History

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