1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-30 15:57:35 -04: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 (
2016-08-20 14:55:45 -04:00
v2net "v2ray.com/core/common/net"
2015-12-02 10:19:39 -05:00
)
2016-11-27 15:39:09 -05:00
func (v *Assert) Address(value v2net.Address) *AddressSubject {
2016-05-24 15:55:46 -04:00
return &AddressSubject{
Subject: Subject{
disp: value.String(),
2016-11-27 15:39:09 -05:00
a: v,
2016-05-24 15:55:46 -04:00
},
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) {
2016-11-27 03:19:52 -05:00
if subject.value == another {
2016-05-24 15:55:46 -04:00
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-11-27 03:19:52 -05:00
if subject.value != 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
}
}