From 0a2e4343bc9bf53e3da0733f288bc6d81bef9c05 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 2 Dec 2015 14:27:18 +0000 Subject: [PATCH] massive refactoring against unit test lib --- .../rules/config/json/fieldrule_test.go | 21 ++--- app/router/rules/router_test.go | 5 +- common/alloc/buffer_test.go | 7 +- common/collect/timed_queue_test.go | 5 +- common/log/access_test.go | 5 +- common/log/log_test.go | 7 +- common/net/address_test.go | 11 +-- common/net/destination_test.go | 7 +- common/net/json/network_test.go | 7 +- common/net/json/portrange_test.go | 13 ++-- common/net/testing/assert/portsubject.go | 46 +++++++++++ common/net/transport_test.go | 5 +- common/retry/retry_test.go | 11 +-- proxy/common/config/json/config_cache_test.go | 6 +- proxy/dokodemo/dokodemo_test.go | 7 +- proxy/freedom/freedom_test.go | 7 +- proxy/socks/config/json/config_test.go | 12 +-- proxy/socks/protocol/socks4_test.go | 7 +- proxy/socks/protocol/socks_test.go | 17 +++-- proxy/socks/protocol/udp_test.go | 6 +- proxy/socks/socks_test.go | 13 ++-- proxy/vmess/config/id_test.go | 4 +- proxy/vmess/protocol/user/rand_test.go | 4 +- proxy/vmess/protocol/vmess_test.go | 7 +- proxy/vmess/vmess_test.go | 5 +- shell/point/config/json/json_test.go | 9 ++- testing/{unit => assert}/boolsubject.go | 15 ++-- testing/{unit => assert}/bytessubject.go | 15 ++-- testing/{unit => assert}/bytesubject.go | 15 ++-- testing/{unit => assert}/errorsubject.go | 15 ++-- testing/{unit => assert}/int64subject.go | 15 ++-- testing/{unit => assert}/intsubject.go | 13 ++-- testing/{unit => assert}/pointersubject.go | 15 ++-- testing/{unit => assert}/stringsubject.go | 15 ++-- testing/assert/subject.go | 33 ++++++++ testing/{unit => assert}/uint16subject.go | 15 ++-- testing/global.go | 66 ++++++++++++++++ testing/scenarios/socks_end_test.go | 9 ++- testing/unit/assertions.go | 53 ------------- testing/unit/subject.go | 76 ------------------- tools/build/build_test.go | 4 +- tools/build/env_test.go | 6 +- tools/build/go_test.go | 4 +- tools/git/git_test.go | 6 +- 44 files changed, 327 insertions(+), 317 deletions(-) create mode 100644 common/net/testing/assert/portsubject.go rename testing/{unit => assert}/boolsubject.go (85%) rename testing/{unit => assert}/bytessubject.go (82%) rename testing/{unit => assert}/bytesubject.go (86%) rename testing/{unit => assert}/errorsubject.go (85%) rename testing/{unit => assert}/int64subject.go (87%) rename testing/{unit => assert}/intsubject.go (87%) rename testing/{unit => assert}/pointersubject.go (85%) rename testing/{unit => assert}/stringsubject.go (79%) create mode 100644 testing/assert/subject.go rename testing/{unit => assert}/uint16subject.go (87%) create mode 100644 testing/global.go delete mode 100644 testing/unit/assertions.go delete mode 100644 testing/unit/subject.go diff --git a/app/router/rules/config/json/fieldrule_test.go b/app/router/rules/config/json/fieldrule_test.go index 7e3345f21..da2090f66 100644 --- a/app/router/rules/config/json/fieldrule_test.go +++ b/app/router/rules/config/json/fieldrule_test.go @@ -6,11 +6,12 @@ import ( v2net "github.com/v2ray/v2ray-core/common/net" v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestStringListParsingList(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawJson := `["a", "b", "c", "d"]` var strList StringList @@ -20,7 +21,7 @@ func TestStringListParsingList(t *testing.T) { } func TestStringListParsingString(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawJson := `"abcd"` var strList StringList @@ -30,7 +31,7 @@ func TestStringListParsingString(t *testing.T) { } func TestDomainMatching(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rule := &FieldRule{ Domain: NewStringList("v2ray.com"), @@ -40,7 +41,7 @@ func TestDomainMatching(t *testing.T) { } func TestPortMatching(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rule := &FieldRule{ Port: &v2nettesting.PortRange{ @@ -53,7 +54,7 @@ func TestPortMatching(t *testing.T) { } func TestIPMatching(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawJson := `{ "type": "field", @@ -66,7 +67,7 @@ func TestIPMatching(t *testing.T) { } func TestIPListMatching(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawJson := `{ "type": "field", @@ -79,7 +80,7 @@ func TestIPListMatching(t *testing.T) { } func TestPortNotMatching(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawJson := `{ "type": "field", @@ -92,7 +93,7 @@ func TestPortNotMatching(t *testing.T) { } func TestDomainNotMatching(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawJson := `{ "type": "field", @@ -105,7 +106,7 @@ func TestDomainNotMatching(t *testing.T) { } func TestDomainNotMatchingDomain(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawJson := `{ "type": "field", diff --git a/app/router/rules/router_test.go b/app/router/rules/router_test.go index ee222c381..b01cfb75e 100644 --- a/app/router/rules/router_test.go +++ b/app/router/rules/router_test.go @@ -6,11 +6,12 @@ import ( "github.com/v2ray/v2ray-core/app/router/rules/config" testinconfig "github.com/v2ray/v2ray-core/app/router/rules/config/testing" v2net "github.com/v2ray/v2ray-core/common/net" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestSimpleRouter(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) router := &Router{ rules: []config.Rule{ diff --git a/common/alloc/buffer_test.go b/common/alloc/buffer_test.go index ab3da3c4f..77ee7a1c6 100644 --- a/common/alloc/buffer_test.go +++ b/common/alloc/buffer_test.go @@ -3,11 +3,12 @@ package alloc import ( "testing" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestBufferClear(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) buffer := NewBuffer().Clear() defer buffer.Release() @@ -21,7 +22,7 @@ func TestBufferClear(t *testing.T) { } func TestBufferIsFull(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) buffer := NewBuffer() defer buffer.Release() diff --git a/common/collect/timed_queue_test.go b/common/collect/timed_queue_test.go index 162e0b6dd..8ab9e7640 100644 --- a/common/collect/timed_queue_test.go +++ b/common/collect/timed_queue_test.go @@ -4,11 +4,12 @@ import ( "testing" "time" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestTimedQueue(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) removed := make(map[string]bool) diff --git a/common/log/access_test.go b/common/log/access_test.go index cb58cec96..361168efd 100644 --- a/common/log/access_test.go +++ b/common/log/access_test.go @@ -7,11 +7,12 @@ import ( "testing" "time" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestAccessLog(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) filename := "/tmp/test_access_log.log" InitAccessLogger(filename) diff --git a/common/log/log_test.go b/common/log/log_test.go index 0ae58db9b..31498d766 100644 --- a/common/log/log_test.go +++ b/common/log/log_test.go @@ -5,11 +5,12 @@ import ( "log" "testing" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestLogLevelSetting(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) assert.Pointer(debugLogger).Equals(noOpLoggerInstance) SetLogLevel(DebugLevel) @@ -21,7 +22,7 @@ func TestLogLevelSetting(t *testing.T) { } func TestStreamLogger(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) buffer := bytes.NewBuffer(make([]byte, 0, 1024)) logger := &streamLogger{ diff --git a/common/net/address_test.go b/common/net/address_test.go index 9d5157d7d..87a528182 100644 --- a/common/net/address_test.go +++ b/common/net/address_test.go @@ -4,11 +4,12 @@ import ( "net" "testing" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestIPv4Address(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) ip := []byte{byte(1), byte(2), byte(3), byte(4)} port := NewPort(80) @@ -23,7 +24,7 @@ func TestIPv4Address(t *testing.T) { } func TestIPv6Address(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) ip := []byte{ byte(1), byte(2), byte(3), byte(4), @@ -43,7 +44,7 @@ func TestIPv6Address(t *testing.T) { } func TestDomainAddress(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) domain := "v2ray.com" port := NewPort(443) @@ -58,7 +59,7 @@ func TestDomainAddress(t *testing.T) { } func TestNetIPv4Address(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) ip := net.IPv4(1, 2, 3, 4) port := NewPort(80) diff --git a/common/net/destination_test.go b/common/net/destination_test.go index 2df78392e..9d34ddfd9 100644 --- a/common/net/destination_test.go +++ b/common/net/destination_test.go @@ -3,11 +3,12 @@ package net import ( "testing" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestTCPDestination(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) dest := NewTCPDestination(IPAddress([]byte{1, 2, 3, 4}, 80)) assert.Bool(dest.IsTCP()).IsTrue() @@ -16,7 +17,7 @@ func TestTCPDestination(t *testing.T) { } func TestUDPDestination(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) dest := NewUDPDestination(IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}, 53)) assert.Bool(dest.IsTCP()).IsFalse() diff --git a/common/net/json/network_test.go b/common/net/json/network_test.go index 32d77cebb..cf7064c9b 100644 --- a/common/net/json/network_test.go +++ b/common/net/json/network_test.go @@ -4,11 +4,12 @@ import ( "encoding/json" "testing" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestArrayNetworkList(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var list NetworkList err := json.Unmarshal([]byte("[\"Tcp\"]"), &list) @@ -18,7 +19,7 @@ func TestArrayNetworkList(t *testing.T) { } func TestStringNetworkList(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var list NetworkList err := json.Unmarshal([]byte("\"TCP, ip\""), &list) diff --git a/common/net/json/portrange_test.go b/common/net/json/portrange_test.go index 125ce2acc..eb3641c79 100644 --- a/common/net/json/portrange_test.go +++ b/common/net/json/portrange_test.go @@ -4,11 +4,12 @@ import ( "encoding/json" "testing" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestIntPort(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var portRange PortRange err := json.Unmarshal([]byte("1234"), &portRange) @@ -19,7 +20,7 @@ func TestIntPort(t *testing.T) { } func TestOverRangeIntPort(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var portRange PortRange err := json.Unmarshal([]byte("70000"), &portRange) @@ -30,7 +31,7 @@ func TestOverRangeIntPort(t *testing.T) { } func TestSingleStringPort(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var portRange PortRange err := json.Unmarshal([]byte("\"1234\""), &portRange) @@ -41,7 +42,7 @@ func TestSingleStringPort(t *testing.T) { } func TestStringPairPort(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var portRange PortRange err := json.Unmarshal([]byte("\"1234-5678\""), &portRange) @@ -52,7 +53,7 @@ func TestStringPairPort(t *testing.T) { } func TestOverRangeStringPort(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var portRange PortRange err := json.Unmarshal([]byte("\"65536\""), &portRange) diff --git a/common/net/testing/assert/portsubject.go b/common/net/testing/assert/portsubject.go new file mode 100644 index 000000000..4f219b580 --- /dev/null +++ b/common/net/testing/assert/portsubject.go @@ -0,0 +1,46 @@ +package unit + +import ( + v2net "github.com/v2ray/v2ray-core/common/net" + "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) Fail(verb string, other v2net.Port) { + subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other.String() + ">.") +} + +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("is equal to", expectation) + } +} + +func (subject *PortSubject) GreaterThan(expectation v2net.Port) { + if subject.value.Value() <= expectation.Value() { + subject.Fail("is greater than", expectation) + } +} + +func (subject *PortSubject) LessThan(expectation v2net.Port) { + if subject.value.Value() >= expectation.Value() { + subject.Fail("is less than", expectation) + } +} diff --git a/common/net/transport_test.go b/common/net/transport_test.go index 4c5492338..f1984a12e 100644 --- a/common/net/transport_test.go +++ b/common/net/transport_test.go @@ -8,11 +8,12 @@ import ( "testing" "github.com/v2ray/v2ray-core/common/alloc" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestReaderAndWrite(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) size := 1024 * 1024 buffer := make([]byte, size) diff --git a/common/retry/retry_test.go b/common/retry/retry_test.go index 1c0be1a9a..33bb47b8f 100644 --- a/common/retry/retry_test.go +++ b/common/retry/retry_test.go @@ -5,7 +5,8 @@ import ( "testing" "time" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) var ( @@ -13,7 +14,7 @@ var ( ) func TestNoRetry(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) startTime := time.Now().Unix() err := Timed(10, 100000).On(func() error { @@ -26,7 +27,7 @@ func TestNoRetry(t *testing.T) { } func TestRetryOnce(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) startTime := time.Now() called := 0 @@ -44,7 +45,7 @@ func TestRetryOnce(t *testing.T) { } func TestRetryMultiple(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) startTime := time.Now() called := 0 @@ -62,7 +63,7 @@ func TestRetryMultiple(t *testing.T) { } func TestRetryExhausted(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) startTime := time.Now() called := 0 diff --git a/proxy/common/config/json/config_cache_test.go b/proxy/common/config/json/config_cache_test.go index 7ac3574ff..361e06f70 100644 --- a/proxy/common/config/json/config_cache_test.go +++ b/proxy/common/config/json/config_cache_test.go @@ -4,11 +4,11 @@ import ( "testing" "github.com/v2ray/v2ray-core/proxy/common/config" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestRegisterInboundConfig(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) initializeConfigCache() protocol := "test_protocol" @@ -27,7 +27,7 @@ func TestRegisterInboundConfig(t *testing.T) { } func TestRegisterOutboundConfig(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) initializeConfigCache() protocol := "test_protocol" diff --git a/proxy/dokodemo/dokodemo_test.go b/proxy/dokodemo/dokodemo_test.go index bd570325c..e5ea38013 100644 --- a/proxy/dokodemo/dokodemo_test.go +++ b/proxy/dokodemo/dokodemo_test.go @@ -10,13 +10,14 @@ import ( _ "github.com/v2ray/v2ray-core/proxy/freedom" "github.com/v2ray/v2ray-core/shell/point" "github.com/v2ray/v2ray-core/shell/point/config/testing/mocks" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/udp" - "github.com/v2ray/v2ray-core/testing/unit" ) func TestDokodemoTCP(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() @@ -78,7 +79,7 @@ func TestDokodemoTCP(t *testing.T) { } func TestDokodemoUDP(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() diff --git a/proxy/freedom/freedom_test.go b/proxy/freedom/freedom_test.go index 1c73e7afd..9607e50b0 100644 --- a/proxy/freedom/freedom_test.go +++ b/proxy/freedom/freedom_test.go @@ -18,13 +18,14 @@ import ( proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks" "github.com/v2ray/v2ray-core/shell/point" "github.com/v2ray/v2ray-core/shell/point/config/testing/mocks" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/udp" - "github.com/v2ray/v2ray-core/testing/unit" ) func TestUDPSend(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) data2Send := "Data to be sent to remote" @@ -76,7 +77,7 @@ func TestUDPSend(t *testing.T) { } func TestSocksTcpConnect(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() data2Send := "Data to be sent to remote" diff --git a/proxy/socks/config/json/config_test.go b/proxy/socks/config/json/config_test.go index 0e9c11b33..8229de9aa 100644 --- a/proxy/socks/config/json/config_test.go +++ b/proxy/socks/config/json/config_test.go @@ -7,11 +7,11 @@ import ( "github.com/v2ray/v2ray-core/proxy/common/config" jsonconfig "github.com/v2ray/v2ray-core/proxy/common/config/json" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestAccountMapParsing(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var accountMap SocksAccountMap err := json.Unmarshal([]byte("[{\"user\": \"a\", \"pass\":\"b\"}, {\"user\": \"c\", \"pass\":\"d\"}]"), &accountMap) @@ -24,14 +24,14 @@ func TestAccountMapParsing(t *testing.T) { } func TestDefaultIPAddress(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) socksConfig := jsonconfig.CreateConfig("socks", config.TypeInbound).(*SocksConfig) assert.String(socksConfig.IP().String()).Equals("127.0.0.1") } func TestIPAddressParsing(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var ipAddress IPAddress err := json.Unmarshal([]byte("\"1.2.3.4\""), &ipAddress) @@ -40,7 +40,7 @@ func TestIPAddressParsing(t *testing.T) { } func TestNoAuthConfig(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var config SocksConfig err := json.Unmarshal([]byte("{\"auth\":\"noauth\", \"ip\":\"8.8.8.8\"}"), &config) @@ -52,7 +52,7 @@ func TestNoAuthConfig(t *testing.T) { } func TestUserPassConfig(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) var config SocksConfig err := json.Unmarshal([]byte("{\"auth\":\"password\", \"accounts\":[{\"user\":\"x\", \"pass\":\"y\"}], \"udp\":true}"), &config) diff --git a/proxy/socks/protocol/socks4_test.go b/proxy/socks/protocol/socks4_test.go index c61e2ba04..88572b544 100644 --- a/proxy/socks/protocol/socks4_test.go +++ b/proxy/socks/protocol/socks4_test.go @@ -5,11 +5,12 @@ import ( "testing" "github.com/v2ray/v2ray-core/common/alloc" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestSocks4AuthenticationRequestRead(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawRequest := []byte{ 0x04, // version @@ -26,7 +27,7 @@ func TestSocks4AuthenticationRequestRead(t *testing.T) { } func TestSocks4AuthenticationResponseToBytes(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) response := NewSocks4AuthenticationResponse(byte(0x10), 443, []byte{1, 2, 3, 4}) diff --git a/proxy/socks/protocol/socks_test.go b/proxy/socks/protocol/socks_test.go index d501dc192..759edaf7d 100644 --- a/proxy/socks/protocol/socks_test.go +++ b/proxy/socks/protocol/socks_test.go @@ -6,12 +6,13 @@ import ( "testing" "github.com/v2ray/v2ray-core/common/alloc" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/transport" ) func TestHasAuthenticationMethod(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) request := Socks5AuthenticationRequest{ version: socksVersion, @@ -26,7 +27,7 @@ func TestHasAuthenticationMethod(t *testing.T) { } func TestAuthenticationRequestRead(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawRequest := []byte{ 0x05, // version @@ -41,7 +42,7 @@ func TestAuthenticationRequestRead(t *testing.T) { } func TestAuthenticationResponseWrite(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) response := NewAuthenticationResponse(byte(0x05)) @@ -51,7 +52,7 @@ func TestAuthenticationResponseWrite(t *testing.T) { } func TestRequestRead(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rawRequest := []byte{ 0x05, // version @@ -71,7 +72,7 @@ func TestRequestRead(t *testing.T) { } func TestResponseWrite(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) response := Socks5Response{ socksVersion, @@ -98,14 +99,14 @@ func TestResponseWrite(t *testing.T) { } func TestEOF(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) _, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 0))) assert.Error(err).Equals(io.EOF) } func TestSignleByte(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) _, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1))) assert.Error(err).Equals(transport.CorruptedPacket) diff --git a/proxy/socks/protocol/udp_test.go b/proxy/socks/protocol/udp_test.go index 4e4afde7c..fa3828ee8 100644 --- a/proxy/socks/protocol/udp_test.go +++ b/proxy/socks/protocol/udp_test.go @@ -3,12 +3,12 @@ package protocol import ( "testing" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/transport" ) func TestSingleByteRequest(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) request, err := ReadUDPRequest(make([]byte, 1)) if request != nil { @@ -18,7 +18,7 @@ func TestSingleByteRequest(t *testing.T) { } func TestDomainAddressRequest(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) payload := make([]byte, 0, 1024) payload = append(payload, 0, 0, 1, AddrTypeDomain, byte(len("v2ray.com"))) diff --git a/proxy/socks/socks_test.go b/proxy/socks/socks_test.go index 73ecc6e48..4d1934c57 100644 --- a/proxy/socks/socks_test.go +++ b/proxy/socks/socks_test.go @@ -15,11 +15,12 @@ import ( proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks" "github.com/v2ray/v2ray-core/shell/point" "github.com/v2ray/v2ray-core/shell/point/config/testing/mocks" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestSocksTcpConnect(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() connInput := []byte("The data to be returned to socks server.") @@ -74,7 +75,7 @@ func TestSocksTcpConnect(t *testing.T) { } func TestSocksTcpConnectWithUserPass(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() connInput := []byte("The data to be returned to socks server.") @@ -132,7 +133,7 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) { } func TestSocksTcpConnectWithWrongUserPass(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() connInput := []byte("The data to be returned to socks server.") @@ -176,7 +177,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) { } func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() connInput := []byte("The data to be returned to socks server.") @@ -220,7 +221,7 @@ func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) { } func TestSocksUdpSend(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) port := v2nettesting.PickPort() connInput := []byte("The data to be returned to socks server.") diff --git a/proxy/vmess/config/id_test.go b/proxy/vmess/config/id_test.go index 9f547d7bd..c574a6dde 100644 --- a/proxy/vmess/config/id_test.go +++ b/proxy/vmess/config/id_test.go @@ -3,11 +3,11 @@ package config import ( "testing" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestUUIDToID(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) uuid := "2418d087-648d-4990-86e8-19dca1d006d3" expectedBytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3} diff --git a/proxy/vmess/protocol/user/rand_test.go b/proxy/vmess/protocol/user/rand_test.go index b68bb865f..fcbdb8dad 100644 --- a/proxy/vmess/protocol/user/rand_test.go +++ b/proxy/vmess/protocol/user/rand_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestGenerateRandomInt64InRange(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) base := time.Now().Unix() delta := 100 diff --git a/proxy/vmess/protocol/vmess_test.go b/proxy/vmess/protocol/vmess_test.go index 835d02f08..4d714c2d4 100644 --- a/proxy/vmess/protocol/vmess_test.go +++ b/proxy/vmess/protocol/vmess_test.go @@ -10,7 +10,8 @@ import ( "github.com/v2ray/v2ray-core/proxy/vmess/config" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) type TestUser struct { @@ -27,7 +28,7 @@ func (this *TestUser) Level() config.UserLevel { } func TestVMessSerialization(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) userId, err := config.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51") if err != nil { @@ -81,7 +82,7 @@ func TestVMessSerialization(t *testing.T) { } func TestReadSingleByte(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) reader := NewVMessRequestReader(nil) _, err := reader.Read(bytes.NewReader(make([]byte, 1))) diff --git a/proxy/vmess/vmess_test.go b/proxy/vmess/vmess_test.go index 271e88e39..d9c556be8 100644 --- a/proxy/vmess/vmess_test.go +++ b/proxy/vmess/vmess_test.go @@ -12,11 +12,12 @@ import ( "github.com/v2ray/v2ray-core/proxy/vmess/config/json" "github.com/v2ray/v2ray-core/shell/point" "github.com/v2ray/v2ray-core/shell/point/config/testing/mocks" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestVMessInAndOut(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) testAccount, err := config.NewID("ad937d9d-6e23-4a5a-ba23-bce5092a7c51") assert.Error(err).IsNil() diff --git a/shell/point/config/json/json_test.go b/shell/point/config/json/json_test.go index 297c2387a..135eeec2a 100644 --- a/shell/point/config/json/json_test.go +++ b/shell/point/config/json/json_test.go @@ -10,11 +10,12 @@ import ( _ "github.com/v2ray/v2ray-core/proxy/vmess/config/json" "github.com/v2ray/v2ray-core/shell/point/config/json" - "github.com/v2ray/v2ray-core/testing/unit" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestClientSampleConfig(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) // TODO: fix for Windows baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config" @@ -34,7 +35,7 @@ func TestClientSampleConfig(t *testing.T) { } func TestServerSampleConfig(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) // TODO: fix for Windows baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config" @@ -54,7 +55,7 @@ func TestServerSampleConfig(t *testing.T) { } func TestDetourConfig(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) // TODO: fix for Windows baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config" diff --git a/testing/unit/boolsubject.go b/testing/assert/boolsubject.go similarity index 85% rename from testing/unit/boolsubject.go rename to testing/assert/boolsubject.go index a3f9682e5..aaed7eba4 100644 --- a/testing/unit/boolsubject.go +++ b/testing/assert/boolsubject.go @@ -1,19 +1,16 @@ -package unit +package assert import ( "strconv" ) -type BoolSubject struct { - *Subject - value bool +func Bool(value bool) *BoolSubject { + return &BoolSubject{value: value} } -func NewBoolSubject(base *Subject, value bool) *BoolSubject { - return &BoolSubject{ - Subject: base, - value: value, - } +type BoolSubject struct { + Subject + value bool } func (subject *BoolSubject) Named(name string) *BoolSubject { diff --git a/testing/unit/bytessubject.go b/testing/assert/bytessubject.go similarity index 82% rename from testing/unit/bytessubject.go rename to testing/assert/bytessubject.go index b20b928f8..07c86aaf8 100644 --- a/testing/unit/bytessubject.go +++ b/testing/assert/bytessubject.go @@ -1,20 +1,17 @@ -package unit +package assert import ( "bytes" "fmt" ) -type BytesSubject struct { - *Subject - value []byte +func Bytes(value []byte) *BytesSubject { + return &BytesSubject{value: value} } -func NewBytesSubject(base *Subject, value []byte) *BytesSubject { - return &BytesSubject{ - Subject: base, - value: value, - } +type BytesSubject struct { + Subject + value []byte } func (subject *BytesSubject) Named(name string) *BytesSubject { diff --git a/testing/unit/bytesubject.go b/testing/assert/bytesubject.go similarity index 86% rename from testing/unit/bytesubject.go rename to testing/assert/bytesubject.go index be3a1e2d8..6a7b60acf 100644 --- a/testing/unit/bytesubject.go +++ b/testing/assert/bytesubject.go @@ -1,19 +1,16 @@ -package unit +package assert import ( "strconv" ) -type ByteSubject struct { - *Subject - value byte +func Byte(value byte) *ByteSubject { + return &ByteSubject{value: value} } -func NewByteSubject(base *Subject, value byte) *ByteSubject { - return &ByteSubject{ - Subject: base, - value: value, - } +type ByteSubject struct { + Subject + value byte } func (subject *ByteSubject) Named(name string) *ByteSubject { diff --git a/testing/unit/errorsubject.go b/testing/assert/errorsubject.go similarity index 85% rename from testing/unit/errorsubject.go rename to testing/assert/errorsubject.go index 420b1bec8..2acaab6f6 100644 --- a/testing/unit/errorsubject.go +++ b/testing/assert/errorsubject.go @@ -1,15 +1,12 @@ -package unit +package assert -type ErrorSubject struct { - *Subject - value error +func Error(value error) *ErrorSubject { + return &ErrorSubject{value: value} } -func NewErrorSubject(base *Subject, value error) *ErrorSubject { - return &ErrorSubject{ - Subject: base, - value: value, - } +type ErrorSubject struct { + Subject + value error } func (subject *ErrorSubject) Named(name string) *ErrorSubject { diff --git a/testing/unit/int64subject.go b/testing/assert/int64subject.go similarity index 87% rename from testing/unit/int64subject.go rename to testing/assert/int64subject.go index 59c3d9c8b..4b3414a62 100644 --- a/testing/unit/int64subject.go +++ b/testing/assert/int64subject.go @@ -1,19 +1,16 @@ -package unit +package assert import ( "strconv" ) -type Int64Subject struct { - *Subject - value int64 +func Int64(value int64) *Int64Subject { + return &Int64Subject{value: value} } -func NewInt64Subject(base *Subject, value int64) *Int64Subject { - return &Int64Subject{ - Subject: base, - value: value, - } +type Int64Subject struct { + Subject + value int64 } func (subject *Int64Subject) Named(name string) *Int64Subject { diff --git a/testing/unit/intsubject.go b/testing/assert/intsubject.go similarity index 87% rename from testing/unit/intsubject.go rename to testing/assert/intsubject.go index 358bd22d3..fe52adcec 100644 --- a/testing/unit/intsubject.go +++ b/testing/assert/intsubject.go @@ -1,21 +1,18 @@ -package unit +package assert import ( "strconv" ) +func Int(value int) *IntSubject { + return &IntSubject{value: value} +} + type IntSubject struct { *Subject value int } -func NewIntSubject(base *Subject, value int) *IntSubject { - return &IntSubject{ - Subject: base, - value: value, - } -} - func (subject *IntSubject) Named(name string) *IntSubject { subject.Subject.Named(name) return subject diff --git a/testing/unit/pointersubject.go b/testing/assert/pointersubject.go similarity index 85% rename from testing/unit/pointersubject.go rename to testing/assert/pointersubject.go index e7ed60bfb..5faa37249 100644 --- a/testing/unit/pointersubject.go +++ b/testing/assert/pointersubject.go @@ -1,19 +1,16 @@ -package unit +package assert import ( "fmt" ) -type PointerSubject struct { - *Subject - value interface{} +func Pointer(value interface{}) *PointerSubject { + return &PointerSubject{value: value} } -func NewPointerSubject(base *Subject, value interface{}) *PointerSubject { - return &PointerSubject{ - Subject: base, - value: value, - } +type PointerSubject struct { + Subject + value interface{} } func (subject *PointerSubject) Named(name string) *PointerSubject { diff --git a/testing/unit/stringsubject.go b/testing/assert/stringsubject.go similarity index 79% rename from testing/unit/stringsubject.go rename to testing/assert/stringsubject.go index 8c24f741d..1a9b8e822 100644 --- a/testing/unit/stringsubject.go +++ b/testing/assert/stringsubject.go @@ -1,15 +1,12 @@ -package unit +package assert -type StringSubject struct { - *Subject - value string +func String(value string) *StringSubject { + return &StringSubject{value: value} } -func NewStringSubject(base *Subject, value string) *StringSubject { - return &StringSubject{ - Subject: base, - value: value, - } +type StringSubject struct { + Subject + value string } func (subject *StringSubject) Named(name string) *StringSubject { diff --git a/testing/assert/subject.go b/testing/assert/subject.go new file mode 100644 index 000000000..b851c726b --- /dev/null +++ b/testing/assert/subject.go @@ -0,0 +1,33 @@ +package assert + +import ( + v2testing "github.com/v2ray/v2ray-core/testing" +) + +type Subject struct { + name string +} + +func NewSubject() *Subject { + return &Subject{ + name: "", + } +} + +func (subject *Subject) FailWithMessage(message string) { + v2testing.Fail(message) +} + +func (subject *Subject) Named(name string) { + subject.name = name +} + +func (subject *Subject) DisplayString(value string) string { + if len(value) == 0 { + value = "unknown" + } + if len(subject.name) == 0 { + return "<" + value + ">" + } + return subject.name + "(<" + value + ">)" +} diff --git a/testing/unit/uint16subject.go b/testing/assert/uint16subject.go similarity index 87% rename from testing/unit/uint16subject.go rename to testing/assert/uint16subject.go index 588fb0327..ad10b4432 100644 --- a/testing/unit/uint16subject.go +++ b/testing/assert/uint16subject.go @@ -1,19 +1,16 @@ -package unit +package assert import ( "strconv" ) -type Uint16Subject struct { - *Subject - value uint16 +func Uint16(value uint16) *Uint16Subject { + return &Uint16Subject{value: value} } -func NewUint16Subject(base *Subject, value uint16) *Uint16Subject { - return &Uint16Subject{ - Subject: base, - value: value, - } +type Uint16Subject struct { + Subject + value uint16 } func (subject *Uint16Subject) Named(name string) *Uint16Subject { diff --git a/testing/global.go b/testing/global.go new file mode 100644 index 000000000..39ea234b6 --- /dev/null +++ b/testing/global.go @@ -0,0 +1,66 @@ +package unit + +import ( + "bytes" + "fmt" + "runtime" + "strings" + "testing" +) + +var tGlobal *testing.T + +func Current(t *testing.T) { + tGlobal = t +} + +func getCaller() (string, int) { + stackLevel := 3 + for { + _, file, line, ok := runtime.Caller(stackLevel) + if strings.Contains(file, "assert") { + stackLevel++ + } else { + if ok { + // Truncate file name at last file name separator. + if index := strings.LastIndex(file, "/"); index >= 0 { + file = file[index+1:] + } else if index = strings.LastIndex(file, "\\"); index >= 0 { + file = file[index+1:] + } + } else { + file = "???" + line = 1 + } + return file, line + } + } +} + +// decorate prefixes the string with the file and line of the call site +// and inserts the final newline if needed and indentation tabs for formatting. +func decorate(s string) string { + file, line := getCaller() + buf := new(bytes.Buffer) + // Every line is indented at least one tab. + buf.WriteString(" ") + fmt.Fprintf(buf, "%s:%d: ", file, line) + lines := strings.Split(s, "\n") + if l := len(lines); l > 1 && lines[l-1] == "" { + lines = lines[:l-1] + } + for i, line := range lines { + if i > 0 { + // Second and subsequent lines are indented an extra tab. + buf.WriteString("\n\t\t") + } + buf.WriteString(line) + } + buf.WriteByte('\n') + return buf.String() +} + +func Fail(message string) { + fmt.Println(decorate(message)) + tGlobal.Fail() +} diff --git a/testing/scenarios/socks_end_test.go b/testing/scenarios/socks_end_test.go index 993ec3e08..de1bf82fc 100644 --- a/testing/scenarios/socks_end_test.go +++ b/testing/scenarios/socks_end_test.go @@ -6,13 +6,14 @@ import ( v2net "github.com/v2ray/v2ray-core/common/net" v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/udp" - "github.com/v2ray/v2ray-core/testing/unit" ) func TestTCPConnection(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) targetPort := v2nettesting.PickPort() tcpServer := &tcp.Server{ @@ -78,7 +79,7 @@ func TestTCPConnection(t *testing.T) { } func TestTCPBind(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) targetPort := v2nettesting.PickPort() tcpServer := &tcp.Server{ @@ -125,7 +126,7 @@ func TestTCPBind(t *testing.T) { } func TestUDPAssociate(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) targetPort := v2nettesting.PickPort() udpServer := &udp.Server{ diff --git a/testing/unit/assertions.go b/testing/unit/assertions.go deleted file mode 100644 index 1b10d1b9e..000000000 --- a/testing/unit/assertions.go +++ /dev/null @@ -1,53 +0,0 @@ -package unit - -import ( - "testing" -) - -// Assertion is an assertion library inspired by Truth. -// See http://google.github.io/truth/ -type Assertion struct { - t *testing.T -} - -func Assert(t *testing.T) *Assertion { - assert := new(Assertion) - assert.t = t - return assert -} - -func (a *Assertion) Int64(value int64) *Int64Subject { - return NewInt64Subject(NewSubject(a), value) -} - -func (a *Assertion) Int(value int) *IntSubject { - return NewIntSubject(NewSubject(a), value) -} - -func (a *Assertion) Uint16(value uint16) *Uint16Subject { - return NewUint16Subject(NewSubject(a), value) -} - -func (a *Assertion) Byte(value byte) *ByteSubject { - return NewByteSubject(NewSubject(a), value) -} - -func (a *Assertion) Bytes(value []byte) *BytesSubject { - return NewBytesSubject(NewSubject(a), value) -} - -func (a *Assertion) String(value string) *StringSubject { - return NewStringSubject(NewSubject(a), value) -} - -func (a *Assertion) Error(value error) *ErrorSubject { - return NewErrorSubject(NewSubject(a), value) -} - -func (a *Assertion) Bool(value bool) *BoolSubject { - return NewBoolSubject(NewSubject(a), value) -} - -func (a *Assertion) Pointer(value interface{}) *PointerSubject { - return NewPointerSubject(NewSubject(a), value) -} diff --git a/testing/unit/subject.go b/testing/unit/subject.go deleted file mode 100644 index 1d803ed2d..000000000 --- a/testing/unit/subject.go +++ /dev/null @@ -1,76 +0,0 @@ -package unit - -import ( - "bytes" - "fmt" - "runtime" - "strings" -) - -type Subject struct { - assert *Assertion - name string -} - -func NewSubject(assert *Assertion) *Subject { - return &Subject{ - assert: assert, - name: "", - } -} - -// decorate prefixes the string with the file and line of the call site -// and inserts the final newline if needed and indentation tabs for formatting. -func decorate(s string) string { - _, file, line, ok := runtime.Caller(3) - if strings.Contains(file, "testing") { - _, file, line, ok = runtime.Caller(4) - } - if ok { - // Truncate file name at last file name separator. - if index := strings.LastIndex(file, "/"); index >= 0 { - file = file[index+1:] - } else if index = strings.LastIndex(file, "\\"); index >= 0 { - file = file[index+1:] - } - } else { - file = "???" - line = 1 - } - buf := new(bytes.Buffer) - // Every line is indented at least one tab. - buf.WriteString(" ") - fmt.Fprintf(buf, "%s:%d: ", file, line) - lines := strings.Split(s, "\n") - if l := len(lines); l > 1 && lines[l-1] == "" { - lines = lines[:l-1] - } - for i, line := range lines { - if i > 0 { - // Second and subsequent lines are indented an extra tab. - buf.WriteString("\n\t\t") - } - buf.WriteString(line) - } - buf.WriteByte('\n') - return buf.String() -} - -func (subject *Subject) FailWithMessage(message string) { - fmt.Println(decorate(message)) - subject.assert.t.Fail() -} - -func (subject *Subject) Named(name string) { - subject.name = name -} - -func (subject *Subject) DisplayString(value string) string { - if len(value) == 0 { - value = "unknown" - } - if len(subject.name) == 0 { - return "<" + value + ">" - } - return subject.name + "(<" + value + ">)" -} diff --git a/tools/build/build_test.go b/tools/build/build_test.go index 19c7092f4..1bbec1aad 100644 --- a/tools/build/build_test.go +++ b/tools/build/build_test.go @@ -6,7 +6,7 @@ import ( "path/filepath" "testing" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func cleanBinPath() { @@ -31,7 +31,7 @@ func allFilesExists(files ...string) bool { } func TestBuildMacOS(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) binPath = filepath.Join(os.Getenv("GOPATH"), "testing") cleanBinPath() diff --git a/tools/build/env_test.go b/tools/build/env_test.go index 45c22e605..53acdb2ac 100644 --- a/tools/build/env_test.go +++ b/tools/build/env_test.go @@ -3,11 +3,11 @@ package main import ( "testing" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestParseOS(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) assert.Pointer(parseOS("windows")).Equals(Windows) assert.Pointer(parseOS("macos")).Equals(MacOS) @@ -16,7 +16,7 @@ func TestParseOS(t *testing.T) { } func TestParseArch(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) assert.Pointer(parseArch("x86")).Equals(X86) assert.Pointer(parseArch("x64")).Equals(Amd64) diff --git a/tools/build/go_test.go b/tools/build/go_test.go index 65785ae0d..7f9b5a66f 100644 --- a/tools/build/go_test.go +++ b/tools/build/go_test.go @@ -11,11 +11,11 @@ import ( "testing" "time" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestBuildAndRun(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) gopath := os.Getenv("GOPATH") target := filepath.Join(gopath, "src", "v2ray_test") diff --git a/tools/git/git_test.go b/tools/git/git_test.go index 4fd69ea59..e2b5dae92 100644 --- a/tools/git/git_test.go +++ b/tools/git/git_test.go @@ -3,11 +3,11 @@ package git import ( "testing" - "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/testing/assert" ) func TestRevParse(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) rev, err := RevParse("HEAD") assert.Error(err).IsNil() @@ -15,7 +15,7 @@ func TestRevParse(t *testing.T) { } func TestRepoVersion(t *testing.T) { - assert := unit.Assert(t) + v2testing.Current(t) version, err := RepoVersionHead() assert.Error(err).IsNil()