1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 11:35:23 +00:00
v2fly/testing/assert/address.go

81 lines
1.6 KiB
Go
Raw Normal View History

2015-12-02 16:27:55 +00:00
package assert
2015-12-02 15:19:39 +00:00
import (
2017-01-13 23:27:45 +00:00
"v2ray.com/core/common/net"
2015-12-02 15:19:39 +00:00
)
2017-01-13 23:27:45 +00:00
func (v *Assert) Address(value net.Address) *AddressSubject {
2016-05-24 19:55:46 +00:00
return &AddressSubject{
Subject: Subject{
disp: value.String(),
2016-11-27 20:39:09 +00:00
a: v,
2016-05-24 19:55:46 +00:00
},
value: value,
}
2015-12-02 15:19:39 +00:00
}
type AddressSubject struct {
2016-05-24 13:29:08 +00:00
Subject
2017-01-13 23:27:45 +00:00
value net.Address
2015-12-02 15:19:39 +00:00
}
2017-01-13 23:27:45 +00:00
func (subject *AddressSubject) NotEquals(another net.Address) {
2016-11-27 08:19:52 +00:00
if subject.value == another {
2016-05-24 19:55:46 +00:00
subject.Fail("not equals to", another.String())
}
2015-12-02 15:19:39 +00:00
}
2017-01-13 23:27:45 +00:00
func (subject *AddressSubject) Equals(another net.Address) {
2016-11-27 08:19:52 +00:00
if subject.value != another {
2016-05-24 19:55:46 +00:00
subject.Fail("equals to", another.String())
}
}
func (subject *AddressSubject) NotEqualsString(another string) {
if subject.value.String() == another {
subject.Fail("not equals to string", another)
}
}
func (subject *AddressSubject) EqualsString(another string) {
if subject.value.String() != another {
subject.Fail("equals to string", another)
2015-12-25 00:07:42 +00:00
}
}
2015-12-02 15:19:39 +00:00
func (subject *AddressSubject) IsIPv4() {
2016-08-14 16:14:12 +00:00
if !subject.value.Family().IsIPv4() {
2016-05-24 19:55:46 +00:00
subject.Fail("is", "an IPv4 address")
2015-12-02 15:19:39 +00:00
}
}
func (subject *AddressSubject) IsNotIPv4() {
2016-08-14 16:14:12 +00:00
if subject.value.Family().IsIPv4() {
2016-05-24 19:55:46 +00:00
subject.Fail("is not", "an IPv4 address")
2015-12-02 15:19:39 +00:00
}
}
func (subject *AddressSubject) IsIPv6() {
2016-08-14 16:14:12 +00:00
if !subject.value.Family().IsIPv6() {
2016-05-24 19:55:46 +00:00
subject.Fail("is", "an IPv6 address")
2015-12-02 15:19:39 +00:00
}
}
func (subject *AddressSubject) IsNotIPv6() {
2016-08-14 16:14:12 +00:00
if subject.value.Family().IsIPv6() {
2016-05-24 19:55:46 +00:00
subject.Fail("is not", "an IPv6 address")
2015-12-02 15:19:39 +00:00
}
}
func (subject *AddressSubject) IsDomain() {
2016-08-14 16:14:12 +00:00
if !subject.value.Family().IsDomain() {
2016-05-24 19:55:46 +00:00
subject.Fail("is", "a domain address")
2015-12-02 15:19:39 +00:00
}
}
func (subject *AddressSubject) IsNotDomain() {
2016-08-14 16:14:12 +00:00
if subject.value.Family().IsDomain() {
2016-05-24 19:55:46 +00:00
subject.Fail("is not", "a domain address")
2015-12-02 15:19:39 +00:00
}
}