From fa7c1069bc91a6fcd00042d35372f04b297c9cc7 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 2 Dec 2015 16:27:55 +0000 Subject: [PATCH] more update --- common/net/address_test.go | 4 +- common/net/destination_test.go | 9 +++-- common/net/testing/assert/address.go | 2 +- common/net/testing/assert/destination.go | 49 ++++++++++++++++++++++++ common/net/testing/assert/port.go | 2 +- proxy/socks/protocol/udp_test.go | 2 +- proxy/vmess/config/id_test.go | 2 +- proxy/vmess/protocol/user/rand_test.go | 2 +- testing/assert/stringsubject.go | 4 +- tools/build/build_test.go | 2 +- tools/build/env_test.go | 2 +- tools/build/go_test.go | 2 +- tools/git/git_test.go | 2 +- 13 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 common/net/testing/assert/destination.go diff --git a/common/net/address_test.go b/common/net/address_test.go index 611024fc..6319acb9 100644 --- a/common/net/address_test.go +++ b/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") } diff --git a/common/net/destination_test.go b/common/net/destination_test.go index 391ebe5c..f1691392 100644 --- a/common/net/destination_test.go +++ b/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") } diff --git a/common/net/testing/assert/address.go b/common/net/testing/assert/address.go index 581a05c9..b0d22652 100644 --- a/common/net/testing/assert/address.go +++ b/common/net/testing/assert/address.go @@ -1,4 +1,4 @@ -package unit +package assert import ( v2net "github.com/v2ray/v2ray-core/common/net" diff --git a/common/net/testing/assert/destination.go b/common/net/testing/assert/destination.go new file mode 100644 index 00000000..054ca352 --- /dev/null +++ b/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")) + } +} diff --git a/common/net/testing/assert/port.go b/common/net/testing/assert/port.go index e83813b8..6a697bca 100644 --- a/common/net/testing/assert/port.go +++ b/common/net/testing/assert/port.go @@ -1,4 +1,4 @@ -package unit +package assert import ( v2net "github.com/v2ray/v2ray-core/common/net" diff --git a/proxy/socks/protocol/udp_test.go b/proxy/socks/protocol/udp_test.go index 51f1f1a3..0ad79817 100644 --- a/proxy/socks/protocol/udp_test.go +++ b/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" ) diff --git a/proxy/vmess/config/id_test.go b/proxy/vmess/config/id_test.go index f99e0277..568e9df7 100644 --- a/proxy/vmess/config/id_test.go +++ b/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" ) diff --git a/proxy/vmess/protocol/user/rand_test.go b/proxy/vmess/protocol/user/rand_test.go index a01b941f..9122b97e 100644 --- a/proxy/vmess/protocol/user/rand_test.go +++ b/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" ) diff --git a/testing/assert/stringsubject.go b/testing/assert/stringsubject.go index 09d02673..aa904a82 100644 --- a/testing/assert/stringsubject.go +++ b/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 { diff --git a/tools/build/build_test.go b/tools/build/build_test.go index aa6ffa64..471b43af 100644 --- a/tools/build/build_test.go +++ b/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" ) diff --git a/tools/build/env_test.go b/tools/build/env_test.go index 116cc69d..fccbd435 100644 --- a/tools/build/env_test.go +++ b/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" ) diff --git a/tools/build/go_test.go b/tools/build/go_test.go index 56656303..6a623540 100644 --- a/tools/build/go_test.go +++ b/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" ) diff --git a/tools/git/git_test.go b/tools/git/git_test.go index 31e3cd38..df8c3413 100644 --- a/tools/git/git_test.go +++ b/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" )