1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-18 01:46:06 -04:00
v2fly/testing/assert/address.go

81 lines
1.6 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 (
2017-01-13 18:27:45 -05:00
"v2ray.com/core/common/net"
2015-12-02 10:19:39 -05:00
)
2017-01-13 18:27:45 -05:00
func (v *Assert) Address(value net.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
2017-01-13 18:27:45 -05:00
value net.Address
2015-12-02 10:19:39 -05:00
}
2017-01-13 18:27:45 -05:00
func (subject *AddressSubject) NotEquals(another net.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
}
2017-01-13 18:27:45 -05:00
func (subject *AddressSubject) Equals(another net.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
}
}