1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00
v2fly/common/net/testing/assert.go

49 lines
1.1 KiB
Go
Raw Normal View History

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
}