1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 17:38:45 -05:00
v2fly/testing/assert/address.go

81 lines
1.7 KiB
Go
Raw Normal View History

2015-12-02 11:27:55 -05:00
package assert
2015-12-02 10:19:39 -05:00
import (
v2net "github.com/v2ray/v2ray-core/common/net"
)
2016-05-24 15:55:46 -04:00
func (this *Assert) Address(value v2net.Address) *AddressSubject {
return &AddressSubject{
Subject: Subject{
disp: value.String(),
a: this,
},
value: value,
}
2015-12-02 10:19:39 -05:00
}
type AddressSubject struct {
2016-05-24 09:29:08 -04:00
Subject
2015-12-02 10:19:39 -05:00
value v2net.Address
}
2016-05-24 15:55:46 -04:00
func (subject *AddressSubject) NotEquals(another v2net.Address) {
if subject.value.Equals(another) {
subject.Fail("not equals to", another.String())
}
2015-12-02 10:19:39 -05:00
}
2015-12-24 19:07:42 -05:00
func (subject *AddressSubject) Equals(another v2net.Address) {
2016-01-29 09:09:51 -05:00
if !subject.value.Equals(another) {
2016-05-24 15:55:46 -04: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-24 19:07:42 -05:00
}
}
2015-12-02 10:19:39 -05:00
func (subject *AddressSubject) IsIPv4() {
2016-08-14 12:14:12 -04:00
if !subject.value.Family().IsIPv4() {
2016-05-24 15:55:46 -04:00
subject.Fail("is", "an IPv4 address")
2015-12-02 10:19:39 -05:00
}
}
func (subject *AddressSubject) IsNotIPv4() {
2016-08-14 12:14:12 -04:00
if subject.value.Family().IsIPv4() {
2016-05-24 15:55:46 -04:00
subject.Fail("is not", "an IPv4 address")
2015-12-02 10:19:39 -05:00
}
}
func (subject *AddressSubject) IsIPv6() {
2016-08-14 12:14:12 -04:00
if !subject.value.Family().IsIPv6() {
2016-05-24 15:55:46 -04:00
subject.Fail("is", "an IPv6 address")
2015-12-02 10:19:39 -05:00
}
}
func (subject *AddressSubject) IsNotIPv6() {
2016-08-14 12:14:12 -04:00
if subject.value.Family().IsIPv6() {
2016-05-24 15:55:46 -04:00
subject.Fail("is not", "an IPv6 address")
2015-12-02 10:19:39 -05:00
}
}
func (subject *AddressSubject) IsDomain() {
2016-08-14 12:14:12 -04:00
if !subject.value.Family().IsDomain() {
2016-05-24 15:55:46 -04:00
subject.Fail("is", "a domain address")
2015-12-02 10:19:39 -05:00
}
}
func (subject *AddressSubject) IsNotDomain() {
2016-08-14 12:14:12 -04:00
if subject.value.Family().IsDomain() {
2016-05-24 15:55:46 -04:00
subject.Fail("is not", "a domain address")
2015-12-02 10:19:39 -05:00
}
}