1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-06 09:15:37 -05:00

simplify testing

This commit is contained in:
v2ray
2016-05-24 21:55:46 +02:00
parent 3582b9d869
commit fc63f0432c
99 changed files with 726 additions and 817 deletions

View File

@@ -2,11 +2,16 @@ package assert
import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
)
func Destination(value v2net.Destination) *DestinationSubject {
return &DestinationSubject{value: value}
func (this *Assert) Destination(value v2net.Destination) *DestinationSubject {
return &DestinationSubject{
Subject: Subject{
disp: value.String(),
a: this,
},
value: value,
}
}
type DestinationSubject struct {
@@ -14,35 +19,40 @@ type DestinationSubject struct {
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"))
this.Fail("is", "a TCP destination")
}
}
func (this *DestinationSubject) IsNotTCP() {
if this.value.IsTCP() {
this.Fail(this.DisplayString(), "is not", serial.StringT("a TCP destination"))
this.Fail("is not", "a TCP destination")
}
}
func (this *DestinationSubject) IsUDP() {
if !this.value.IsUDP() {
this.Fail(this.DisplayString(), "is", serial.StringT("a UDP destination"))
this.Fail("is", "a UDP destination")
}
}
func (this *DestinationSubject) IsNotUDP() {
if this.value.IsUDP() {
this.Fail(this.DisplayString(), "is not", serial.StringT("a UDP destination"))
this.Fail("is not", "a UDP destination")
}
}
func (this *DestinationSubject) EqualsString(another string) {
if this.value.String() != another {
this.Fail("not equals to string", another)
}
}
func (this *DestinationSubject) HasAddress() *AddressSubject {
return this.a.Address(this.value.Address())
}
func (this *DestinationSubject) HasPort() *PortSubject {
return this.a.Port(this.value.Port())
}