1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 15:36:41 -05:00

more update

This commit is contained in:
Darien Raymond 2015-12-02 16:27:55 +00:00
parent ec31c1fa7f
commit fa7c1069bc
13 changed files with 67 additions and 17 deletions

View File

@ -41,7 +41,7 @@ func TestIPv6Address(t *testing.T) {
v2netassert.Address(addr).IsNotIPv4() v2netassert.Address(addr).IsNotIPv4()
v2netassert.Address(addr).IsNotDomain() v2netassert.Address(addr).IsNotDomain()
assert.Bytes(addr.IP()).Equals(ip) assert.Bytes(addr.IP()).Equals(ip)
assert.Uint16(addr.Port().Value()).Equals(port.Value()) v2netassert.Port(addr.Port()).Equals(port)
assert.String(addr).Equals("[102:304:102:304:102:304:102:304]:443") assert.String(addr).Equals("[102:304:102:304:102:304:102:304]:443")
} }
@ -56,7 +56,7 @@ func TestDomainAddress(t *testing.T) {
v2netassert.Address(addr).IsNotIPv6() v2netassert.Address(addr).IsNotIPv6()
v2netassert.Address(addr).IsNotIPv4() v2netassert.Address(addr).IsNotIPv4()
assert.StringLiteral(addr.Domain()).Equals(domain) assert.StringLiteral(addr.Domain()).Equals(domain)
assert.Uint16(addr.Port().Value()).Equals(port.Value()) v2netassert.Port(addr.Port()).Equals(port)
assert.String(addr).Equals("v2ray.com:443") assert.String(addr).Equals("v2ray.com:443")
} }

View File

@ -4,6 +4,7 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
v2testing "github.com/v2ray/v2ray-core/testing" v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
@ -12,8 +13,8 @@ func TestTCPDestination(t *testing.T) {
v2testing.Current(t) v2testing.Current(t)
dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}, 80)) dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}, 80))
assert.Bool(dest.IsTCP()).IsTrue() v2netassert.Destination(dest).IsTCP()
assert.Bool(dest.IsUDP()).IsFalse() v2netassert.Destination(dest).IsNotUDP()
assert.String(dest).Equals("tcp:1.2.3.4:80") assert.String(dest).Equals("tcp:1.2.3.4:80")
} }
@ -21,7 +22,7 @@ func TestUDPDestination(t *testing.T) {
v2testing.Current(t) v2testing.Current(t)
dest := v2net.NewUDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}, 53)) dest := v2net.NewUDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}, 53))
assert.Bool(dest.IsTCP()).IsFalse() v2netassert.Destination(dest).IsNotTCP()
assert.Bool(dest.IsUDP()).IsTrue() v2netassert.Destination(dest).IsUDP()
assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53") assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53")
} }

View File

@ -1,4 +1,4 @@
package unit package assert
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"

View File

@ -0,0 +1,49 @@
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.StringLiteral("a TCP destination"))
}
}
func (this *DestinationSubject) IsNotTCP() {
if this.value.IsTCP() {
this.Fail(this.DisplayString(), "is not", serial.StringLiteral("a TCP destination"))
}
}
func (this *DestinationSubject) IsUDP() {
if !this.value.IsUDP() {
this.Fail(this.DisplayString(), "is", serial.StringLiteral("a UDP destination"))
}
}
func (this *DestinationSubject) IsNotUDP() {
if this.value.IsUDP() {
this.Fail(this.DisplayString(), "is not", serial.StringLiteral("a UDP destination"))
}
}

View File

@ -1,4 +1,4 @@
package unit package assert
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"