浏览代码

more update

Darien Raymond 10 年之前
父节点
当前提交
fa7c1069bc

+ 2 - 2
common/net/address_test.go

@@ -41,7 +41,7 @@ func TestIPv6Address(t *testing.T) {
 	v2netassert.Address(addr).IsNotIPv4()
 	v2netassert.Address(addr).IsNotDomain()
 	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")
 }
 
@@ -56,7 +56,7 @@ func TestDomainAddress(t *testing.T) {
 	v2netassert.Address(addr).IsNotIPv6()
 	v2netassert.Address(addr).IsNotIPv4()
 	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")
 }
 

+ 5 - 4
common/net/destination_test.go

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

+ 1 - 1
common/net/testing/assert/address.go

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

+ 49 - 0
common/net/testing/assert/destination.go

@@ -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"))
+	}
+}

+ 1 - 1
common/net/testing/assert/port.go

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

+ 1 - 1
proxy/socks/protocol/udp_test.go

@@ -3,7 +3,7 @@ package protocol
 import (
 	"testing"
 
-  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/transport"
 )

+ 1 - 1
proxy/vmess/config/id_test.go

@@ -3,7 +3,7 @@ package config
 import (
 	"testing"
 
-  v2testing "github.com/v2ray/v2ray-core/testing"
+	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
 

+ 1 - 1
proxy/vmess/protocol/user/rand_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"time"
 
-  v2testing "github.com/v2ray/v2ray-core/testing"
+	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
 

+ 2 - 2
testing/assert/stringsubject.go

@@ -1,11 +1,11 @@
 package assert
 
 import (
-  "github.com/v2ray/v2ray-core/common/serial"
+	"github.com/v2ray/v2ray-core/common/serial"
 )
 
 func StringLiteral(value string) *StringSubject {
-  return String(serial.StringLiteral((value)))
+	return String(serial.StringLiteral((value)))
 }
 
 func String(value serial.String) *StringSubject {

+ 1 - 1
tools/build/build_test.go

@@ -6,7 +6,7 @@ import (
 	"path/filepath"
 	"testing"
 
-  v2testing "github.com/v2ray/v2ray-core/testing"
+	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
 

+ 1 - 1
tools/build/env_test.go

@@ -3,7 +3,7 @@ package main
 import (
 	"testing"
 
-  v2testing "github.com/v2ray/v2ray-core/testing"
+	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
 

+ 1 - 1
tools/build/go_test.go

@@ -11,7 +11,7 @@ import (
 	"testing"
 	"time"
 
-  v2testing "github.com/v2ray/v2ray-core/testing"
+	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )
 

+ 1 - 1
tools/git/git_test.go

@@ -3,7 +3,7 @@ package git
 import (
 	"testing"
 
-  v2testing "github.com/v2ray/v2ray-core/testing"
+	v2testing "github.com/v2ray/v2ray-core/testing"
 	"github.com/v2ray/v2ray-core/testing/assert"
 )