mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-02-12 19:25:25 -05:00
move net/testing/assert into assert
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func Address(value v2net.Address) *AddressSubject {
|
||||
return &AddressSubject{value: value}
|
||||
}
|
||||
|
||||
type AddressSubject struct {
|
||||
assert.Subject
|
||||
value v2net.Address
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) Named(name string) *AddressSubject {
|
||||
subject.Subject.Named(name)
|
||||
return subject
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) DisplayString() string {
|
||||
return subject.Subject.DisplayString(subject.value.String())
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) Equals(another v2net.Address) {
|
||||
if !subject.value.Equals(another) {
|
||||
subject.Fail(subject.DisplayString(), "equals to", another)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) IsIPv4() {
|
||||
if !subject.value.IsIPv4() {
|
||||
subject.Fail(subject.DisplayString(), "is", serial.StringT("an IPv4 address"))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) IsNotIPv4() {
|
||||
if subject.value.IsIPv4() {
|
||||
subject.Fail(subject.DisplayString(), "is not", serial.StringT("an IPv4 address"))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) IsIPv6() {
|
||||
if !subject.value.IsIPv6() {
|
||||
subject.Fail(subject.DisplayString(), "is", serial.StringT("an IPv6 address"))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) IsNotIPv6() {
|
||||
if subject.value.IsIPv6() {
|
||||
subject.Fail(subject.DisplayString(), "is not", serial.StringT("an IPv6 address"))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) IsDomain() {
|
||||
if !subject.value.IsDomain() {
|
||||
subject.Fail(subject.DisplayString(), "is", serial.StringT("a domain address"))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *AddressSubject) IsNotDomain() {
|
||||
if subject.value.IsDomain() {
|
||||
subject.Fail(subject.DisplayString(), "is not", serial.StringT("a domain address"))
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func Destination(value v2net.Destination) *DestinationSubject {
|
||||
return &DestinationSubject{value: value}
|
||||
}
|
||||
|
||||
type DestinationSubject struct {
|
||||
assert.Subject
|
||||
value v2net.Destination
|
||||
}
|
||||
|
||||
func (this *DestinationSubject) Named(name string) *DestinationSubject {
|
||||
this.Subject.Named(name)
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *DestinationSubject) DisplayString() string {
|
||||
return this.Subject.DisplayString(this.value.String())
|
||||
}
|
||||
|
||||
func (this *DestinationSubject) IsTCP() {
|
||||
if !this.value.IsTCP() {
|
||||
this.Fail(this.DisplayString(), "is", serial.StringT("a TCP destination"))
|
||||
}
|
||||
}
|
||||
|
||||
func (this *DestinationSubject) IsNotTCP() {
|
||||
if this.value.IsTCP() {
|
||||
this.Fail(this.DisplayString(), "is not", serial.StringT("a TCP destination"))
|
||||
}
|
||||
}
|
||||
|
||||
func (this *DestinationSubject) IsUDP() {
|
||||
if !this.value.IsUDP() {
|
||||
this.Fail(this.DisplayString(), "is", serial.StringT("a UDP destination"))
|
||||
}
|
||||
}
|
||||
|
||||
func (this *DestinationSubject) IsNotUDP() {
|
||||
if this.value.IsUDP() {
|
||||
this.Fail(this.DisplayString(), "is not", serial.StringT("a UDP destination"))
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func IP(value net.IP) *IPSubject {
|
||||
return &IPSubject{value: value}
|
||||
}
|
||||
|
||||
type IPSubject struct {
|
||||
assert.Subject
|
||||
value net.IP
|
||||
}
|
||||
|
||||
func (subject *IPSubject) Named(name string) *IPSubject {
|
||||
subject.Subject.Named(name)
|
||||
return subject
|
||||
}
|
||||
|
||||
func (subject *IPSubject) DisplayString() string {
|
||||
return subject.Subject.DisplayString(subject.value.String())
|
||||
}
|
||||
|
||||
func (subject *IPSubject) IsNil() {
|
||||
if subject.value != nil {
|
||||
subject.Fail(subject.DisplayString(), "is", serial.StringT("nil"))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *IPSubject) Equals(ip net.IP) {
|
||||
if !bytes.Equal([]byte(subject.value), []byte(ip)) {
|
||||
subject.Fail(subject.DisplayString(), "equals to", ip)
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func Port(value v2net.Port) *PortSubject {
|
||||
return &PortSubject{value: value}
|
||||
}
|
||||
|
||||
type PortSubject struct {
|
||||
assert.Subject
|
||||
value v2net.Port
|
||||
}
|
||||
|
||||
func (subject *PortSubject) Named(name string) *PortSubject {
|
||||
subject.Subject.Named(name)
|
||||
return subject
|
||||
}
|
||||
|
||||
func (subject *PortSubject) DisplayString() string {
|
||||
return subject.Subject.DisplayString(subject.value.String())
|
||||
}
|
||||
|
||||
func (subject *PortSubject) Equals(expectation v2net.Port) {
|
||||
if subject.value.Value() != expectation.Value() {
|
||||
subject.Fail(subject.DisplayString(), "is equal to", expectation)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *PortSubject) GreaterThan(expectation v2net.Port) {
|
||||
if subject.value.Value() <= expectation.Value() {
|
||||
subject.Fail(subject.DisplayString(), "is greater than", expectation)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *PortSubject) LessThan(expectation v2net.Port) {
|
||||
if subject.value.Value() >= expectation.Value() {
|
||||
subject.Fail(subject.DisplayString(), "is less than", expectation)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *PortSubject) IsValid() {
|
||||
if subject.value == 0 {
|
||||
subject.Fail(subject.DisplayString(), "is", serial.StringT("a valid port"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user