1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -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

@ -8,12 +8,11 @@ import (
. "github.com/v2ray/v2ray-core/app/dns" . "github.com/v2ray/v2ray-core/app/dns"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestConfigParsing(t *testing.T) { func TestConfigParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := `{ rawJson := `{
"servers": ["8.8.8.8"] "servers": ["8.8.8.8"]

View File

@ -11,12 +11,11 @@ import (
"github.com/v2ray/v2ray-core/app/proxyman" "github.com/v2ray/v2ray-core/app/proxyman"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/freedom" "github.com/v2ray/v2ray-core/proxy/freedom"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestDnsAdd(t *testing.T) { func TestDnsAdd(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
space := app.NewSpace() space := app.NewSpace()

View File

@ -6,18 +6,17 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/app/router/rules" . "github.com/v2ray/v2ray-core/app/router/rules"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestChinaIPJson(t *testing.T) { func TestChinaIPJson(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rule := ParseRule([]byte(`{ rule := ParseRule([]byte(`{
"type": "chinaip", "type": "chinaip",
"outboundTag": "x" "outboundTag": "x"
}`)) }`))
assert.StringLiteral(rule.Tag).Equals("x") assert.String(rule.Tag).Equals("x")
assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn
assert.Bool(rule.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com assert.Bool(rule.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com
assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com

View File

@ -6,7 +6,6 @@ import (
. "github.com/v2ray/v2ray-core/app/router/rules" . "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
@ -15,7 +14,7 @@ func makeDestination(ip string) v2net.Destination {
} }
func TestChinaIP(t *testing.T) { func TestChinaIP(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rule := NewChinaIPRule("tag") rule := NewChinaIPRule("tag")
assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn

View File

@ -6,18 +6,17 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/app/router/rules" . "github.com/v2ray/v2ray-core/app/router/rules"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestChinaSitesJson(t *testing.T) { func TestChinaSitesJson(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rule := ParseRule([]byte(`{ rule := ParseRule([]byte(`{
"type": "chinasites", "type": "chinasites",
"outboundTag": "y" "outboundTag": "y"
}`)) }`))
assert.StringLiteral(rule.Tag).Equals("y") assert.String(rule.Tag).Equals("y")
assert.Bool(rule.Apply(makeDomainDestination("v.qq.com"))).IsTrue() assert.Bool(rule.Apply(makeDomainDestination("v.qq.com"))).IsTrue()
assert.Bool(rule.Apply(makeDomainDestination("www.163.com"))).IsTrue() assert.Bool(rule.Apply(makeDomainDestination("www.163.com"))).IsTrue()
assert.Bool(rule.Apply(makeDomainDestination("ngacn.cc"))).IsTrue() assert.Bool(rule.Apply(makeDomainDestination("ngacn.cc"))).IsTrue()

View File

@ -5,7 +5,6 @@ import (
. "github.com/v2ray/v2ray-core/app/router/rules" . "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
@ -14,7 +13,7 @@ func makeDomainDestination(domain string) v2net.Destination {
} }
func TestChinaSites(t *testing.T) { func TestChinaSites(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rule := NewChinaSitesRule("tag") rule := NewChinaSitesRule("tag")
assert.Bool(rule.Apply(makeDomainDestination("v.qq.com"))).IsTrue() assert.Bool(rule.Apply(makeDomainDestination("v.qq.com"))).IsTrue()

View File

@ -3,9 +3,9 @@ package rules
import ( import (
"net" "net"
"regexp" "regexp"
"strings"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
) )
type Condition interface { type Condition interface {
@ -63,12 +63,12 @@ func (this *AnyCondition) Len() int {
} }
type PlainDomainMatcher struct { type PlainDomainMatcher struct {
pattern serial.StringT pattern string
} }
func NewPlainDomainMatcher(pattern string) *PlainDomainMatcher { func NewPlainDomainMatcher(pattern string) *PlainDomainMatcher {
return &PlainDomainMatcher{ return &PlainDomainMatcher{
pattern: serial.StringT(pattern), pattern: pattern,
} }
} }
@ -76,8 +76,8 @@ func (this *PlainDomainMatcher) Apply(dest v2net.Destination) bool {
if !dest.Address().IsDomain() { if !dest.Address().IsDomain() {
return false return false
} }
domain := serial.StringT(dest.Address().Domain()) domain := dest.Address().Domain()
return domain.Contains(this.pattern) return strings.Contains(domain, this.pattern)
} }
type RegexpDomainMatcher struct { type RegexpDomainMatcher struct {
@ -98,8 +98,8 @@ func (this *RegexpDomainMatcher) Apply(dest v2net.Destination) bool {
if !dest.Address().IsDomain() { if !dest.Address().IsDomain() {
return false return false
} }
domain := serial.StringT(dest.Address().Domain()) domain := dest.Address().Domain()
return this.pattern.MatchString(domain.ToLower().String()) return this.pattern.MatchString(strings.ToLower(domain))
} }
type CIDRMatcher struct { type CIDRMatcher struct {

View File

@ -7,12 +7,11 @@ import (
. "github.com/v2ray/v2ray-core/app/router/rules" . "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestDomainRule(t *testing.T) { func TestDomainRule(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rule := ParseRule([]byte(`{ rule := ParseRule([]byte(`{
"type": "field", "type": "field",
@ -33,7 +32,7 @@ func TestDomainRule(t *testing.T) {
} }
func TestIPRule(t *testing.T) { func TestIPRule(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rule := ParseRule([]byte(`{ rule := ParseRule([]byte(`{
"type": "field", "type": "field",

View File

@ -108,10 +108,11 @@ func (this *Router) takeDetourWithoutCache(dest v2net.Destination) (string, erro
} }
func (this *Router) TakeDetour(dest v2net.Destination) (string, error) { func (this *Router) TakeDetour(dest v2net.Destination) (string, error) {
rawEntry := this.cache.Get(dest) destStr := dest.String()
rawEntry := this.cache.Get(destStr)
if rawEntry == nil { if rawEntry == nil {
tag, err := this.takeDetourWithoutCache(dest) tag, err := this.takeDetourWithoutCache(dest)
this.cache.Set(dest, newCacheEntry(tag, err)) this.cache.Set(destStr, newCacheEntry(tag, err))
return tag, err return tag, err
} }
entry := rawEntry.(*cacheEntry) entry := rawEntry.(*cacheEntry)

View File

@ -11,12 +11,11 @@ import (
"github.com/v2ray/v2ray-core/app/router" "github.com/v2ray/v2ray-core/app/router"
. "github.com/v2ray/v2ray-core/app/router/rules" . "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestSimpleRouter(t *testing.T) { func TestSimpleRouter(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
config := &RouterRuleConfig{ config := &RouterRuleConfig{
Rules: []*Rule{ Rules: []*Rule{
@ -37,5 +36,5 @@ func TestSimpleRouter(t *testing.T) {
tag, err := r.TakeDetour(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)) tag, err := r.TakeDetour(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80))
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral(tag).Equals("test") assert.String(tag).Equals("test")
} }

View File

@ -4,12 +4,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/alloc" . "github.com/v2ray/v2ray-core/common/alloc"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestBufferClear(t *testing.T) { func TestBufferClear(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := NewBuffer().Clear() buffer := NewBuffer().Clear()
defer buffer.Release() defer buffer.Release()
@ -23,7 +22,7 @@ func TestBufferClear(t *testing.T) {
} }
func TestBufferIsFull(t *testing.T) { func TestBufferIsFull(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := NewBuffer() buffer := NewBuffer()
defer buffer.Release() defer buffer.Release()
@ -35,7 +34,7 @@ func TestBufferIsFull(t *testing.T) {
} }
func TestBufferPrepend(t *testing.T) { func TestBufferPrepend(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := NewBuffer().Clear() buffer := NewBuffer().Clear()
defer buffer.Release() defer buffer.Release()
@ -51,11 +50,11 @@ func TestBufferPrepend(t *testing.T) {
} }
func TestBufferString(t *testing.T) { func TestBufferString(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := NewBuffer().Clear() buffer := NewBuffer().Clear()
defer buffer.Release() defer buffer.Release()
buffer.AppendString("Test String") buffer.AppendString("Test String")
assert.String(buffer).Equals("Test String") assert.String(buffer.String()).Equals("Test String")
} }

View File

@ -3,8 +3,6 @@ package collect
import ( import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/v2ray/v2ray-core/common/serial"
) )
type Validity interface { type Validity interface {
@ -51,9 +49,9 @@ func (this *ValidityMap) cleanup() {
} }
} }
func (this *ValidityMap) Set(key serial.String, value Validity) { func (this *ValidityMap) Set(key string, value Validity) {
this.Lock() this.Lock()
this.cache[key.String()] = value this.cache[key] = value
this.Unlock() this.Unlock()
opCount := atomic.AddInt32(&this.opCount, 1) opCount := atomic.AddInt32(&this.opCount, 1)
if opCount > 1000 { if opCount > 1000 {
@ -62,10 +60,10 @@ func (this *ValidityMap) Set(key serial.String, value Validity) {
} }
} }
func (this *ValidityMap) Get(key serial.String) Validity { func (this *ValidityMap) Get(key string) Validity {
this.RLock() this.RLock()
defer this.RUnlock() defer this.RUnlock()
if value, found := this.cache[key.String()]; found { if value, found := this.cache[key]; found {
return value return value
} }
return nil return nil

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/crypto" . "github.com/v2ray/v2ray-core/common/crypto"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
@ -19,7 +18,7 @@ func mustDecodeHex(s string) []byte {
} }
func TestChaCha20Stream(t *testing.T) { func TestChaCha20Stream(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var cases = []struct { var cases = []struct {
key []byte key []byte
@ -58,7 +57,7 @@ func TestChaCha20Stream(t *testing.T) {
} }
func TestChaCha20Decoding(t *testing.T) { func TestChaCha20Decoding(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
key := make([]byte, 32) key := make([]byte, 32)
rand.Read(key) rand.Read(key)

View File

@ -5,12 +5,11 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io" . "github.com/v2ray/v2ray-core/common/io"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestBufferedReader(t *testing.T) { func TestBufferedReader(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
content := alloc.NewLargeBuffer() content := alloc.NewLargeBuffer()
len := content.Len() len := content.Len()

View File

@ -5,12 +5,11 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io" . "github.com/v2ray/v2ray-core/common/io"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestBufferedWriter(t *testing.T) { func TestBufferedWriter(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
content := alloc.NewLargeBuffer().Clear() content := alloc.NewLargeBuffer().Clear()

View File

@ -6,12 +6,11 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io" . "github.com/v2ray/v2ray-core/common/io"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestAdaptiveReader(t *testing.T) { func TestAdaptiveReader(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawContent := make([]byte, 1024*1024) rawContent := make([]byte, 1024*1024)

View File

@ -7,12 +7,11 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io" . "github.com/v2ray/v2ray-core/common/io"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestAdaptiveWriter(t *testing.T) { func TestAdaptiveWriter(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
lb := alloc.NewLargeBuffer() lb := alloc.NewLargeBuffer()
rand.Read(lb.Value) rand.Read(lb.Value)

View File

@ -1,8 +1,9 @@
package log package log
import ( import (
"fmt"
"github.com/v2ray/v2ray-core/common/log/internal" "github.com/v2ray/v2ray-core/common/log/internal"
"github.com/v2ray/v2ray-core/common/serial"
) )
// AccessStatus is the status of an access request from clients. // AccessStatus is the status of an access request from clients.
@ -29,7 +30,7 @@ func InitAccessLogger(file string) error {
} }
// Access writes an access log. // Access writes an access log.
func Access(from, to serial.String, status AccessStatus, reason serial.String) { func Access(from, to fmt.Stringer, status AccessStatus, reason fmt.Stringer) {
accessLoggerInstance.Log(&internal.AccessLog{ accessLoggerInstance.Log(&internal.AccessLog{
From: from, From: from,
To: to, To: to,

View File

@ -5,12 +5,11 @@ import (
"github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/serial"
) )
type LogEntry interface { type LogEntry interface {
common.Releasable common.Releasable
serial.String fmt.Stringer
} }
type ErrorLog struct { type ErrorLog struct {
@ -37,7 +36,7 @@ func (this *ErrorLog) String() string {
b.AppendString(typedVal) b.AppendString(typedVal)
case *string: case *string:
b.AppendString(*typedVal) b.AppendString(*typedVal)
case serial.String: case fmt.Stringer:
b.AppendString(typedVal.String()) b.AppendString(typedVal.String())
case error: case error:
b.AppendString(typedVal.Error()) b.AppendString(typedVal.Error())
@ -49,10 +48,10 @@ func (this *ErrorLog) String() string {
} }
type AccessLog struct { type AccessLog struct {
From serial.String From fmt.Stringer
To serial.String To fmt.Stringer
Status string Status string
Reason serial.String Reason fmt.Stringer
} }
func (this *AccessLog) Release() { func (this *AccessLog) Release() {

View File

@ -5,12 +5,11 @@ import (
. "github.com/v2ray/v2ray-core/common/log/internal" . "github.com/v2ray/v2ray-core/common/log/internal"
"github.com/v2ray/v2ray-core/common/serial" "github.com/v2ray/v2ray-core/common/serial"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestAccessLog(t *testing.T) { func TestAccessLog(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
entry := &AccessLog{ entry := &AccessLog{
From: serial.StringT("test_from"), From: serial.StringT("test_from"),
@ -20,8 +19,8 @@ func TestAccessLog(t *testing.T) {
} }
entryStr := entry.String() entryStr := entry.String()
assert.StringLiteral(entryStr).Contains(serial.StringT("test_from")) assert.String(entryStr).Contains("test_from")
assert.StringLiteral(entryStr).Contains(serial.StringT("test_to")) assert.String(entryStr).Contains("test_to")
assert.StringLiteral(entryStr).Contains(serial.StringT("test_reason")) assert.String(entryStr).Contains("test_reason")
assert.StringLiteral(entryStr).Contains(serial.StringT("Accepted")) assert.String(entryStr).Contains("Accepted")
} }

View File

@ -8,12 +8,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/net" . "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestIPParsing(t *testing.T) { func TestIPParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := "\"8.8.8.8\"" rawJson := "\"8.8.8.8\""
var address AddressJson var address AddressJson
@ -25,7 +24,7 @@ func TestIPParsing(t *testing.T) {
} }
func TestDomainParsing(t *testing.T) { func TestDomainParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := "\"v2ray.com\"" rawJson := "\"v2ray.com\""
var address AddressJson var address AddressJson
@ -33,11 +32,11 @@ func TestDomainParsing(t *testing.T) {
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Bool(address.Address.IsIPv4()).IsFalse() assert.Bool(address.Address.IsIPv4()).IsFalse()
assert.Bool(address.Address.IsDomain()).IsTrue() assert.Bool(address.Address.IsDomain()).IsTrue()
assert.StringLiteral(address.Address.Domain()).Equals("v2ray.com") assert.String(address.Address.Domain()).Equals("v2ray.com")
} }
func TestInvalidAddressJson(t *testing.T) { func TestInvalidAddressJson(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := "1234" rawJson := "1234"
var address AddressJson var address AddressJson

View File

@ -5,12 +5,11 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestIPv4Address(t *testing.T) { func TestIPv4Address(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
ip := []byte{byte(1), byte(2), byte(3), byte(4)} ip := []byte{byte(1), byte(2), byte(3), byte(4)}
addr := v2net.IPAddress(ip) addr := v2net.IPAddress(ip)
@ -19,11 +18,11 @@ func TestIPv4Address(t *testing.T) {
assert.Address(addr).IsNotIPv6() assert.Address(addr).IsNotIPv6()
assert.Address(addr).IsNotDomain() assert.Address(addr).IsNotDomain()
assert.Bytes(addr.IP()).Equals(ip) assert.Bytes(addr.IP()).Equals(ip)
assert.String(addr).Equals("1.2.3.4") assert.Address(addr).EqualsString("1.2.3.4")
} }
func TestIPv6Address(t *testing.T) { func TestIPv6Address(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
ip := []byte{ ip := []byte{
byte(1), byte(2), byte(3), byte(4), byte(1), byte(2), byte(3), byte(4),
@ -36,12 +35,12 @@ func TestIPv6Address(t *testing.T) {
assert.Address(addr).IsIPv6() assert.Address(addr).IsIPv6()
assert.Address(addr).IsNotIPv4() assert.Address(addr).IsNotIPv4()
assert.Address(addr).IsNotDomain() assert.Address(addr).IsNotDomain()
assert.Bytes(addr.IP()).Equals(ip) assert.IP(addr.IP()).Equals(net.IP(ip))
assert.String(addr).Equals("[102:304:102:304:102:304:102:304]") assert.Address(addr).EqualsString("[102:304:102:304:102:304:102:304]")
} }
func TestIPv4Asv6(t *testing.T) { func TestIPv4Asv6(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
ip := []byte{ ip := []byte{
byte(0), byte(0), byte(0), byte(0), byte(0), byte(0), byte(0), byte(0),
byte(0), byte(0), byte(0), byte(0), byte(0), byte(0), byte(0), byte(0),
@ -49,11 +48,11 @@ func TestIPv4Asv6(t *testing.T) {
byte(1), byte(2), byte(3), byte(4), byte(1), byte(2), byte(3), byte(4),
} }
addr := v2net.IPAddress(ip) addr := v2net.IPAddress(ip)
assert.String(addr).Equals("1.2.3.4") assert.Address(addr).EqualsString("1.2.3.4")
} }
func TestDomainAddress(t *testing.T) { func TestDomainAddress(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
domain := "v2ray.com" domain := "v2ray.com"
addr := v2net.DomainAddress(domain) addr := v2net.DomainAddress(domain)
@ -61,37 +60,37 @@ func TestDomainAddress(t *testing.T) {
assert.Address(addr).IsDomain() assert.Address(addr).IsDomain()
assert.Address(addr).IsNotIPv6() assert.Address(addr).IsNotIPv6()
assert.Address(addr).IsNotIPv4() assert.Address(addr).IsNotIPv4()
assert.StringLiteral(addr.Domain()).Equals(domain) assert.String(addr.Domain()).Equals(domain)
assert.String(addr).Equals("v2ray.com") assert.Address(addr).EqualsString("v2ray.com")
} }
func TestNetIPv4Address(t *testing.T) { func TestNetIPv4Address(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
ip := net.IPv4(1, 2, 3, 4) ip := net.IPv4(1, 2, 3, 4)
addr := v2net.IPAddress(ip) addr := v2net.IPAddress(ip)
assert.Address(addr).IsIPv4() assert.Address(addr).IsIPv4()
assert.String(addr).Equals("1.2.3.4") assert.Address(addr).EqualsString("1.2.3.4")
} }
func TestIPv4AddressEquals(t *testing.T) { func TestIPv4AddressEquals(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
addr := v2net.IPAddress([]byte{1, 2, 3, 4}) addr := v2net.IPAddress([]byte{1, 2, 3, 4})
assert.Bool(addr.Equals(nil)).IsFalse() assert.Address(addr).NotEquals(nil)
addr2 := v2net.IPAddress([]byte{1, 2, 3, 4}) addr2 := v2net.IPAddress([]byte{1, 2, 3, 4})
assert.Bool(addr.Equals(addr2)).IsTrue() assert.Address(addr).Equals(addr2)
addr3 := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6}) addr3 := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Bool(addr.Equals(addr3)).IsFalse() assert.Address(addr).NotEquals(addr3)
addr4 := v2net.IPAddress([]byte{1, 2, 3, 5}) addr4 := v2net.IPAddress([]byte{1, 2, 3, 5})
assert.Bool(addr.Equals(addr4)).IsFalse() assert.Address(addr).NotEquals(addr4)
} }
func TestIPv6AddressEquals(t *testing.T) { func TestIPv6AddressEquals(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
addr := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6}) addr := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Bool(addr.Equals(nil)).IsFalse() assert.Bool(addr.Equals(nil)).IsFalse()
@ -107,7 +106,7 @@ func TestIPv6AddressEquals(t *testing.T) {
} }
func TestDomainAddressEquals(t *testing.T) { func TestDomainAddressEquals(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
addr := v2net.DomainAddress("v2ray.com") addr := v2net.DomainAddress("v2ray.com")
assert.Bool(addr.Equals(nil)).IsFalse() assert.Bool(addr.Equals(nil)).IsFalse()

View File

@ -4,30 +4,29 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestTCPDestination(t *testing.T) { func TestTCPDestination(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80) dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Destination(dest).IsTCP() assert.Destination(dest).IsTCP()
assert.Destination(dest).IsNotUDP() assert.Destination(dest).IsNotUDP()
assert.String(dest).Equals("tcp:1.2.3.4:80") assert.Destination(dest).EqualsString("tcp:1.2.3.4:80")
} }
func TestUDPDestination(t *testing.T) { func TestUDPDestination(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
dest := v2net.UDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53) dest := v2net.UDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53)
assert.Destination(dest).IsNotTCP() assert.Destination(dest).IsNotTCP()
assert.Destination(dest).IsUDP() assert.Destination(dest).IsUDP()
assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53") assert.Destination(dest).EqualsString("udp:[2001:4860:4860::8888]:53")
} }
func TestTCPDestinationEquals(t *testing.T) { func TestTCPDestinationEquals(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80) dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(nil)).IsFalse() assert.Bool(dest.Equals(nil)).IsFalse()
@ -43,7 +42,7 @@ func TestTCPDestinationEquals(t *testing.T) {
} }
func TestUDPDestinationEquals(t *testing.T) { func TestUDPDestinationEquals(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
dest := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80) dest := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(nil)).IsFalse() assert.Bool(dest.Equals(nil)).IsFalse()

View File

@ -5,18 +5,19 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/net" . "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func parseCIDR(str string) *net.IPNet { func parseCIDR(str string) *net.IPNet {
_, ipNet, err := net.ParseCIDR(str) _, ipNet, err := net.ParseCIDR(str)
assert.Error(err).IsNil() if err != nil {
panic(err)
}
return ipNet return ipNet
} }
func TestIPNet(t *testing.T) { func TestIPNet(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
ipNet := NewIPNet() ipNet := NewIPNet()
ipNet.Add(parseCIDR(("0.0.0.0/8"))) ipNet.Add(parseCIDR(("0.0.0.0/8")))

View File

@ -7,12 +7,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/net" . "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestArrayNetworkList(t *testing.T) { func TestArrayNetworkList(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var list NetworkList var list NetworkList
err := json.Unmarshal([]byte("[\"Tcp\"]"), &list) err := json.Unmarshal([]byte("[\"Tcp\"]"), &list)
@ -22,7 +21,7 @@ func TestArrayNetworkList(t *testing.T) {
} }
func TestStringNetworkList(t *testing.T) { func TestStringNetworkList(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var list NetworkList var list NetworkList
err := json.Unmarshal([]byte("\"TCP, ip\""), &list) err := json.Unmarshal([]byte("\"TCP, ip\""), &list)
@ -32,7 +31,7 @@ func TestStringNetworkList(t *testing.T) {
} }
func TestInvalidNetworkJson(t *testing.T) { func TestInvalidNetworkJson(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var list NetworkList var list NetworkList
err := json.Unmarshal([]byte("0"), &list) err := json.Unmarshal([]byte("0"), &list)

View File

@ -13,7 +13,7 @@ var (
) )
// Port represents a network port in TCP and UDP protocol. // Port represents a network port in TCP and UDP protocol.
type Port serial.Uint16Literal type Port uint16
// PortFromBytes converts a byte array to a Port, assuming bytes are in big endian order. // PortFromBytes converts a byte array to a Port, assuming bytes are in big endian order.
// @unsafe Caller must ensure that the byte array has at least 2 elements. // @unsafe Caller must ensure that the byte array has at least 2 elements.
@ -47,12 +47,12 @@ func (this Port) Value() uint16 {
// Bytes returns the correspoding bytes of this Port, in big endian order. // Bytes returns the correspoding bytes of this Port, in big endian order.
func (this Port) Bytes() []byte { func (this Port) Bytes() []byte {
return serial.Uint16Literal(this).Bytes() return serial.Uint16ToBytes(this.Value())
} }
// String returns the string presentation of this Port. // String returns the string presentation of this Port.
func (this Port) String() string { func (this Port) String() string {
return serial.Uint16Literal(this).String() return serial.Uint16ToString(this.Value())
} }
// PortRange represents a range of ports. // PortRange represents a range of ports.

View File

@ -7,12 +7,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/net" . "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestIntPort(t *testing.T) { func TestIntPort(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var portRange PortRange var portRange PortRange
err := json.Unmarshal([]byte("1234"), &portRange) err := json.Unmarshal([]byte("1234"), &portRange)
@ -23,7 +22,7 @@ func TestIntPort(t *testing.T) {
} }
func TestOverRangeIntPort(t *testing.T) { func TestOverRangeIntPort(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var portRange PortRange var portRange PortRange
err := json.Unmarshal([]byte("70000"), &portRange) err := json.Unmarshal([]byte("70000"), &portRange)
@ -34,7 +33,7 @@ func TestOverRangeIntPort(t *testing.T) {
} }
func TestSingleStringPort(t *testing.T) { func TestSingleStringPort(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var portRange PortRange var portRange PortRange
err := json.Unmarshal([]byte("\"1234\""), &portRange) err := json.Unmarshal([]byte("\"1234\""), &portRange)
@ -45,7 +44,7 @@ func TestSingleStringPort(t *testing.T) {
} }
func TestStringPairPort(t *testing.T) { func TestStringPairPort(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var portRange PortRange var portRange PortRange
err := json.Unmarshal([]byte("\"1234-5678\""), &portRange) err := json.Unmarshal([]byte("\"1234-5678\""), &portRange)
@ -56,7 +55,7 @@ func TestStringPairPort(t *testing.T) {
} }
func TestOverRangeStringPort(t *testing.T) { func TestOverRangeStringPort(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var portRange PortRange var portRange PortRange
err := json.Unmarshal([]byte("\"65536\""), &portRange) err := json.Unmarshal([]byte("\"65536\""), &portRange)

View File

@ -4,12 +4,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/net" . "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestPortRangeContains(t *testing.T) { func TestPortRangeContains(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
portRange := &PortRange{ portRange := &PortRange{
From: Port(53), From: Port(53),

View File

@ -4,12 +4,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/net" . "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestTimeOutSettings(t *testing.T) { func TestTimeOutSettings(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
reader := NewTimeOutReader(8, nil) reader := NewTimeOutReader(8, nil)
assert.Int(reader.GetTimeOut()).Equals(8) assert.Int(reader.GetTimeOut()).Equals(8)

View File

@ -2,7 +2,6 @@ package protocol
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
) )
@ -49,7 +48,7 @@ type CommandSwitchAccount struct {
Host v2net.Address Host v2net.Address
Port v2net.Port Port v2net.Port
ID *uuid.UUID ID *uuid.UUID
AlterIds serial.Uint16Literal AlterIds uint16
Level UserLevel Level UserLevel
ValidMin byte ValidMin byte
} }

View File

@ -6,12 +6,11 @@ import (
. "github.com/v2ray/v2ray-core/common/protocol" . "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/serial" "github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestCmdKey(t *testing.T) { func TestCmdKey(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
id := NewID(uuid.New()) id := NewID(uuid.New())
assert.Bool(serial.BytesT(id.CmdKey()).All(0)).IsFalse() assert.Bool(serial.BytesT(id.CmdKey()).All(0)).IsFalse()

View File

@ -99,7 +99,7 @@ func (this *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.
idBytes := cmd.ID.Bytes() idBytes := cmd.ID.Bytes()
writer.Write(idBytes) writer.Write(idBytes)
writer.Write(cmd.AlterIds.Bytes()) writer.Write(serial.Uint16ToBytes(cmd.AlterIds))
writer.Write([]byte{byte(cmd.Level)}) writer.Write([]byte{byte(cmd.Level)})
writer.Write([]byte{cmd.ValidMin}) writer.Write([]byte{cmd.ValidMin})
@ -132,7 +132,7 @@ func (this *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, er
if len(data) < alterIdStart+2 { if len(data) < alterIdStart+2 {
return nil, transport.ErrorCorruptedPacket return nil, transport.ErrorCorruptedPacket
} }
cmd.AlterIds = serial.BytesT(data[alterIdStart : alterIdStart+2]).Uint16() cmd.AlterIds = serial.BytesToUint16(data[alterIdStart : alterIdStart+2])
levelStart := alterIdStart + 2 levelStart := alterIdStart + 2
if len(data) < levelStart+1 { if len(data) < levelStart+1 {
return nil, transport.ErrorCorruptedPacket return nil, transport.ErrorCorruptedPacket

View File

@ -7,12 +7,11 @@ import (
"github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
. "github.com/v2ray/v2ray-core/common/protocol/raw" . "github.com/v2ray/v2ray-core/common/protocol/raw"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestSwitchAccount(t *testing.T) { func TestSwitchAccount(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
sa := &protocol.CommandSwitchAccount{ sa := &protocol.CommandSwitchAccount{
Port: 1234, Port: 1234,
@ -34,8 +33,8 @@ func TestSwitchAccount(t *testing.T) {
assert.Pointer(sa.Host).IsNil() assert.Pointer(sa.Host).IsNil()
assert.Pointer(sa2.Host).IsNil() assert.Pointer(sa2.Host).IsNil()
assert.Port(sa.Port).Equals(sa2.Port) assert.Port(sa.Port).Equals(sa2.Port)
assert.String(sa.ID).Equals(sa2.ID.String()) assert.String(sa.ID.String()).Equals(sa2.ID.String())
assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value()) assert.Uint16(sa.AlterIds).Equals(sa2.AlterIds)
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level)) assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin) assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
} }

View File

@ -8,12 +8,11 @@ import (
"github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
. "github.com/v2ray/v2ray-core/common/protocol/raw" . "github.com/v2ray/v2ray-core/common/protocol/raw"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestRequestSerialization(t *testing.T) { func TestRequestSerialization(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
user := protocol.NewUser( user := protocol.NewUser(
protocol.NewID(uuid.New()), protocol.NewID(uuid.New()),

View File

@ -5,12 +5,11 @@ import (
"time" "time"
. "github.com/v2ray/v2ray-core/common/protocol" . "github.com/v2ray/v2ray-core/common/protocol"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestGenerateRandomInt64InRange(t *testing.T) { func TestGenerateRandomInt64InRange(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
base := time.Now().Unix() base := time.Now().Unix()
delta := 100 delta := 100

View File

@ -7,12 +7,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/protocol" . "github.com/v2ray/v2ray-core/common/protocol"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestUserParsing(t *testing.T) { func TestUserParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
user := new(User) user := new(User)
err := json.Unmarshal([]byte(`{ err := json.Unmarshal([]byte(`{
@ -22,12 +21,12 @@ func TestUserParsing(t *testing.T) {
"alterId": 100 "alterId": 100
}`), user) }`), user)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.String(user.ID).Equals("96edb838-6d68-42ef-a933-25f7ac3a9d09") assert.String(user.ID.String()).Equals("96edb838-6d68-42ef-a933-25f7ac3a9d09")
assert.Byte(byte(user.Level)).Equals(1) assert.Byte(byte(user.Level)).Equals(1)
} }
func TestInvalidUserJson(t *testing.T) { func TestInvalidUserJson(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
user := new(User) user := new(User)
err := json.Unmarshal([]byte(`{"id": 1234}`), user) err := json.Unmarshal([]byte(`{"id": 1234}`), user)
@ -35,7 +34,7 @@ func TestInvalidUserJson(t *testing.T) {
} }
func TestInvalidIdJson(t *testing.T) { func TestInvalidIdJson(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
user := new(User) user := new(User)
err := json.Unmarshal([]byte(`{"id": "1234"}`), user) err := json.Unmarshal([]byte(`{"id": "1234"}`), user)

View File

@ -6,7 +6,6 @@ import (
"time" "time"
. "github.com/v2ray/v2ray-core/common/retry" . "github.com/v2ray/v2ray-core/common/retry"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
@ -15,7 +14,7 @@ var (
) )
func TestNoRetry(t *testing.T) { func TestNoRetry(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
startTime := time.Now().Unix() startTime := time.Now().Unix()
err := Timed(10, 100000).On(func() error { err := Timed(10, 100000).On(func() error {
@ -28,7 +27,7 @@ func TestNoRetry(t *testing.T) {
} }
func TestRetryOnce(t *testing.T) { func TestRetryOnce(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
startTime := time.Now() startTime := time.Now()
called := 0 called := 0
@ -46,7 +45,7 @@ func TestRetryOnce(t *testing.T) {
} }
func TestRetryMultiple(t *testing.T) { func TestRetryMultiple(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
startTime := time.Now() startTime := time.Now()
called := 0 called := 0
@ -64,7 +63,7 @@ func TestRetryMultiple(t *testing.T) {
} }
func TestRetryExhausted(t *testing.T) { func TestRetryExhausted(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
startTime := time.Now() startTime := time.Now()
called := 0 called := 0

View File

@ -2,10 +2,24 @@ package serial
import ( import (
"bytes" "bytes"
"encoding/hex"
"strings"
) )
type Bytes interface { func ByteToHexString(value byte) string {
Bytes() []byte return hex.EncodeToString([]byte{value})
}
func BytesToUint16(value []byte) uint16 {
return uint16(value[0])<<8 + uint16(value[1])
}
func BytesToHexString(value []byte) string {
strs := make([]string, len(value))
for i, b := range value {
strs[i] = hex.EncodeToString([]byte{b})
}
return "[" + strings.Join(strs, ",") + "]"
} }
type BytesT []byte type BytesT []byte

View File

@ -0,0 +1,9 @@
package serial
import (
"fmt"
)
func PointerToString(value interface{}) string {
return fmt.Sprint(value)
}

View File

@ -4,6 +4,22 @@ import (
"strconv" "strconv"
) )
func Uint16ToBytes(value uint16) []byte {
return []byte{byte(value >> 8), byte(value)}
}
func Uint16ToString(value uint16) string {
return strconv.Itoa(int(value))
}
func IntToString(value int) string {
return Int64ToString(int64(value))
}
func Int64ToString(value int64) string {
return strconv.FormatInt(value, 10)
}
type Uint16 interface { type Uint16 interface {
Value() uint16 Value() uint16
} }

View File

@ -7,12 +7,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/serial" . "github.com/v2ray/v2ray-core/common/serial"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestInvalidStringTJson(t *testing.T) { func TestInvalidStringTJson(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var s StringT var s StringT
err := json.Unmarshal([]byte("1"), &s) err := json.Unmarshal([]byte("1"), &s)
@ -20,10 +19,10 @@ func TestInvalidStringTJson(t *testing.T) {
} }
func TestStringTParsing(t *testing.T) { func TestStringTParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var s StringT var s StringT
err := json.Unmarshal([]byte("\"1\""), &s) err := json.Unmarshal([]byte("\"1\""), &s)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.String(s).Equals("1") assert.String(s.String()).Equals("1")
} }

View File

@ -7,12 +7,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/serial" . "github.com/v2ray/v2ray-core/common/serial"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestStringListUnmarshalError(t *testing.T) { func TestStringListUnmarshalError(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := `1234` rawJson := `1234`
list := new(StringTList) list := new(StringTList)

View File

@ -1,24 +0,0 @@
package serial_test
import (
"testing"
. "github.com/v2ray/v2ray-core/common/serial"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
type TestString struct {
value string
}
func (this *TestString) String() string {
return this.value
}
func TestNewStringSerial(t *testing.T) {
v2testing.Current(t)
testString := &TestString{value: "abcd"}
assert.String(NewStringT(testString)).Equals("abcd")
}

View File

@ -4,26 +4,25 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/common/uuid" . "github.com/v2ray/v2ray-core/common/uuid"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestParseBytes(t *testing.T) { func TestParseBytes(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
str := "2418d087-648d-4990-86e8-19dca1d006d3" str := "2418d087-648d-4990-86e8-19dca1d006d3"
bytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3} bytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3}
uuid, err := ParseBytes(bytes) uuid, err := ParseBytes(bytes)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.String(uuid).Equals(str) assert.String(uuid.String()).Equals(str)
_, err = ParseBytes([]byte{1, 3, 2, 4}) _, err = ParseBytes([]byte{1, 3, 2, 4})
assert.Error(err).Equals(ErrorInvalidID) assert.Error(err).Equals(ErrorInvalidID)
} }
func TestParseString(t *testing.T) { func TestParseString(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
str := "2418d087-648d-4990-86e8-19dca1d006d3" str := "2418d087-648d-4990-86e8-19dca1d006d3"
expectedBytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3} expectedBytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x06, 0xd3}
@ -40,28 +39,28 @@ func TestParseString(t *testing.T) {
} }
func TestNewUUID(t *testing.T) { func TestNewUUID(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
uuid := New() uuid := New()
uuid2, err := ParseString(uuid.String()) uuid2, err := ParseString(uuid.String())
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral(uuid.String()).Equals(uuid2.String()) assert.String(uuid.String()).Equals(uuid2.String())
assert.Bytes(uuid.Bytes()).Equals(uuid2.Bytes()) assert.Bytes(uuid.Bytes()).Equals(uuid2.Bytes())
} }
func TestRandom(t *testing.T) { func TestRandom(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
uuid := New() uuid := New()
uuid2 := New() uuid2 := New()
assert.StringLiteral(uuid.String()).NotEquals(uuid2.String()) assert.String(uuid.String()).NotEquals(uuid2.String())
assert.Bytes(uuid.Bytes()).NotEquals(uuid2.Bytes()) assert.Bytes(uuid.Bytes()).NotEquals(uuid2.Bytes())
} }
func TestEquals(t *testing.T) { func TestEquals(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
var uuid *UUID = nil var uuid *UUID = nil
var uuid2 *UUID = nil var uuid2 *UUID = nil
@ -70,7 +69,7 @@ func TestEquals(t *testing.T) {
} }
func TestNext(t *testing.T) { func TestNext(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
uuid := New() uuid := New()
uuid2 := uuid.Next() uuid2 := uuid.Next()

View File

@ -12,14 +12,13 @@ import (
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
. "github.com/v2ray/v2ray-core/proxy/dokodemo" . "github.com/v2ray/v2ray-core/proxy/dokodemo"
"github.com/v2ray/v2ray-core/proxy/freedom" "github.com/v2ray/v2ray-core/proxy/freedom"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
"github.com/v2ray/v2ray-core/testing/servers/udp" "github.com/v2ray/v2ray-core/testing/servers/udp"
) )
func TestDokodemoTCP(t *testing.T) { func TestDokodemoTCP(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
Port: v2nettesting.PickPort(), Port: v2nettesting.PickPort(),
@ -73,11 +72,11 @@ func TestDokodemoTCP(t *testing.T) {
assert.Error(err).IsNil() assert.Error(err).IsNil()
tcpClient.Close() tcpClient.Close()
assert.StringLiteral("Processed: " + data2Send).Equals(string(response[:nBytes])) assert.String("Processed: " + data2Send).Equals(string(response[:nBytes]))
} }
func TestDokodemoUDP(t *testing.T) { func TestDokodemoUDP(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
udpServer := &udp.Server{ udpServer := &udp.Server{
Port: v2nettesting.PickPort(), Port: v2nettesting.PickPort(),

View File

@ -15,14 +15,13 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
. "github.com/v2ray/v2ray-core/proxy/freedom" . "github.com/v2ray/v2ray-core/proxy/freedom"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
"github.com/v2ray/v2ray-core/transport/ray" "github.com/v2ray/v2ray-core/transport/ray"
) )
func TestSinglePacket(t *testing.T) { func TestSinglePacket(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
port := v2nettesting.PickPort() port := v2nettesting.PickPort()
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
@ -56,7 +55,7 @@ func TestSinglePacket(t *testing.T) {
} }
func TestUnreachableDestination(t *testing.T) { func TestUnreachableDestination(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
freedom := NewFreedomConnection(&Config{}, app.NewSpace()) freedom := NewFreedomConnection(&Config{}, app.NewSpace())
traffic := ray.NewRay() traffic := ray.NewRay()
@ -68,7 +67,7 @@ func TestUnreachableDestination(t *testing.T) {
} }
func TestIPResolution(t *testing.T) { func TestIPResolution(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
space := app.NewSpace() space := app.NewSpace()
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager()) space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())

View File

@ -8,12 +8,11 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
. "github.com/v2ray/v2ray-core/proxy/http" . "github.com/v2ray/v2ray-core/proxy/http"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestOwnHosts(t *testing.T) { func TestOwnHosts(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := `{ rawJson := `{
"ownHosts": [ "ownHosts": [

View File

@ -9,12 +9,11 @@ import (
testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing" testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
. "github.com/v2ray/v2ray-core/proxy/http" . "github.com/v2ray/v2ray-core/proxy/http"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestHopByHopHeadersStrip(t *testing.T) { func TestHopByHopHeadersStrip(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawRequest := `GET /pkg/net/http/ HTTP/1.1 rawRequest := `GET /pkg/net/http/ HTTP/1.1
Host: golang.org Host: golang.org
@ -33,22 +32,22 @@ Accept-Language: de,en;q=0.7,en-us;q=0.3
b := bufio.NewReader(strings.NewReader(rawRequest)) b := bufio.NewReader(strings.NewReader(rawRequest))
req, err := http.ReadRequest(b) req, err := http.ReadRequest(b)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral(req.Header.Get("Foo")).Equals("foo") assert.String(req.Header.Get("Foo")).Equals("foo")
assert.StringLiteral(req.Header.Get("Bar")).Equals("bar") assert.String(req.Header.Get("Bar")).Equals("bar")
assert.StringLiteral(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar") assert.String(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar")
assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("keep-alive") assert.String(req.Header.Get("Proxy-Connection")).Equals("keep-alive")
assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("abc") assert.String(req.Header.Get("Proxy-Authenticate")).Equals("abc")
StripHopByHopHeaders(req) StripHopByHopHeaders(req)
assert.StringLiteral(req.Header.Get("Connection")).Equals("close") assert.String(req.Header.Get("Connection")).Equals("close")
assert.StringLiteral(req.Header.Get("Foo")).Equals("") assert.String(req.Header.Get("Foo")).Equals("")
assert.StringLiteral(req.Header.Get("Bar")).Equals("") assert.String(req.Header.Get("Bar")).Equals("")
assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("") assert.String(req.Header.Get("Proxy-Connection")).Equals("")
assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("") assert.String(req.Header.Get("Proxy-Authenticate")).Equals("")
} }
func TestNormalGetRequest(t *testing.T) { func TestNormalGetRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil) testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)

View File

@ -3,12 +3,11 @@ package config
import ( import (
"testing" "testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestRegisterInboundConfig(t *testing.T) { func TestRegisterInboundConfig(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
initializeConfigCache() initializeConfigCache()
protocol := "test_protocol" protocol := "test_protocol"
@ -29,7 +28,7 @@ func TestRegisterInboundConfig(t *testing.T) {
} }
func TestRegisterOutboundConfig(t *testing.T) { func TestRegisterOutboundConfig(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
initializeConfigCache() initializeConfigCache()
protocol := "test_protocol" protocol := "test_protocol"

View File

@ -6,12 +6,11 @@ import (
"encoding/json" "encoding/json"
"testing" "testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestConfigParsing(t *testing.T) { func TestConfigParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := `{ rawJson := `{
"method": "aes-128-cfb", "method": "aes-128-cfb",

View File

@ -5,12 +5,11 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/proxy/shadowsocks" . "github.com/v2ray/v2ray-core/proxy/shadowsocks"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestNormalChunkReading(t *testing.T) { func TestNormalChunkReading(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewBuffer().Clear().AppendBytes( buffer := alloc.NewBuffer().Clear().AppendBytes(
0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18) 0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18)

View File

@ -7,13 +7,12 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy"
. "github.com/v2ray/v2ray-core/proxy/shadowsocks" . "github.com/v2ray/v2ray-core/proxy/shadowsocks"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/transport" "github.com/v2ray/v2ray-core/transport"
) )
func TestNormalRequestParsing(t *testing.T) { func TestNormalRequestParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear() buffer := alloc.NewSmallBuffer().Clear()
buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80) buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80)
@ -26,7 +25,7 @@ func TestNormalRequestParsing(t *testing.T) {
} }
func TestEmptyPayload(t *testing.T) { func TestEmptyPayload(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear() buffer := alloc.NewSmallBuffer().Clear()
_, err := ReadRequest(buffer, nil, false) _, err := ReadRequest(buffer, nil, false)
@ -34,7 +33,7 @@ func TestEmptyPayload(t *testing.T) {
} }
func TestSingleBytePayload(t *testing.T) { func TestSingleBytePayload(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1) buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1)
_, err := ReadRequest(buffer, nil, false) _, err := ReadRequest(buffer, nil, false)
@ -42,7 +41,7 @@ func TestSingleBytePayload(t *testing.T) {
} }
func TestWrongAddressType(t *testing.T) { func TestWrongAddressType(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(5) buffer := alloc.NewSmallBuffer().Clear().AppendBytes(5)
_, err := ReadRequest(buffer, nil, false) _, err := ReadRequest(buffer, nil, false)
@ -50,7 +49,7 @@ func TestWrongAddressType(t *testing.T) {
} }
func TestInsufficientAddressRequest(t *testing.T) { func TestInsufficientAddressRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1) buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1)
_, err := ReadRequest(buffer, nil, false) _, err := ReadRequest(buffer, nil, false)
@ -66,7 +65,7 @@ func TestInsufficientAddressRequest(t *testing.T) {
} }
func TestInsufficientPortRequest(t *testing.T) { func TestInsufficientPortRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1, 2, 3, 4, 5) buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1, 2, 3, 4, 5)
_, err := ReadRequest(buffer, nil, false) _, err := ReadRequest(buffer, nil, false)
@ -74,7 +73,7 @@ func TestInsufficientPortRequest(t *testing.T) {
} }
func TestOTARequest(t *testing.T) { func TestOTARequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear() buffer := alloc.NewSmallBuffer().Clear()
buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 0) buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 0)
@ -89,7 +88,7 @@ func TestOTARequest(t *testing.T) {
} }
func TestInvalidOTARequest(t *testing.T) { func TestInvalidOTARequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear() buffer := alloc.NewSmallBuffer().Clear()
buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 1) buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 1)
@ -102,7 +101,7 @@ func TestInvalidOTARequest(t *testing.T) {
} }
func TestUDPRequestParsing(t *testing.T) { func TestUDPRequestParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear() buffer := alloc.NewSmallBuffer().Clear()
buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80, 1, 2, 3, 4, 5, 6) buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80, 1, 2, 3, 4, 5, 6)
@ -116,7 +115,7 @@ func TestUDPRequestParsing(t *testing.T) {
} }
func TestUDPRequestWithOTA(t *testing.T) { func TestUDPRequestWithOTA(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewSmallBuffer().Clear() buffer := alloc.NewSmallBuffer().Clear()
buffer.AppendBytes( buffer.AppendBytes(

View File

@ -7,16 +7,15 @@ import (
"github.com/v2ray/v2ray-core/proxy/internal/config" "github.com/v2ray/v2ray-core/proxy/internal/config"
"github.com/v2ray/v2ray-core/proxy/socks" "github.com/v2ray/v2ray-core/proxy/socks"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestDefaultIPAddress(t *testing.T) { func TestDefaultIPAddress(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
socksConfig, err := config.CreateInboundConfig("socks", []byte(`{ socksConfig, err := config.CreateInboundConfig("socks", []byte(`{
"auth": "noauth" "auth": "noauth"
}`)) }`))
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.String(socksConfig.(*socks.Config).Address).Equals("127.0.0.1") assert.Address(socksConfig.(*socks.Config).Address).EqualsString("127.0.0.1")
} }

View File

@ -6,12 +6,11 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestSocks4AuthenticationRequestRead(t *testing.T) { func TestSocks4AuthenticationRequestRead(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawRequest := []byte{ rawRequest := []byte{
0x04, // version 0x04, // version
@ -21,14 +20,14 @@ func TestSocks4AuthenticationRequestRead(t *testing.T) {
} }
_, request4, err := ReadAuthentication(bytes.NewReader(rawRequest)) _, request4, err := ReadAuthentication(bytes.NewReader(rawRequest))
assert.Error(err).Equals(Socks4Downgrade) assert.Error(err).Equals(Socks4Downgrade)
assert.Byte(request4.Version).Named("Version").Equals(0x04) assert.Byte(request4.Version).Equals(0x04)
assert.Byte(request4.Command).Named("Command").Equals(0x01) assert.Byte(request4.Command).Equals(0x01)
assert.Port(request4.Port).Named("Port").Equals(v2net.Port(53)) assert.Port(request4.Port).Equals(v2net.Port(53))
assert.Bytes(request4.IP[:]).Named("IP").Equals([]byte{0x72, 0x72, 0x72, 0x72}) assert.Bytes(request4.IP[:]).Equals([]byte{0x72, 0x72, 0x72, 0x72})
} }
func TestSocks4AuthenticationResponseToBytes(t *testing.T) { func TestSocks4AuthenticationResponseToBytes(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
response := NewSocks4AuthenticationResponse(byte(0x10), 443, []byte{1, 2, 3, 4}) response := NewSocks4AuthenticationResponse(byte(0x10), 443, []byte{1, 2, 3, 4})

View File

@ -8,13 +8,12 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/transport" "github.com/v2ray/v2ray-core/transport"
) )
func TestHasAuthenticationMethod(t *testing.T) { func TestHasAuthenticationMethod(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
request := Socks5AuthenticationRequest{ request := Socks5AuthenticationRequest{
version: socksVersion, version: socksVersion,
@ -29,7 +28,7 @@ func TestHasAuthenticationMethod(t *testing.T) {
} }
func TestAuthenticationRequestRead(t *testing.T) { func TestAuthenticationRequestRead(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewBuffer().Clear().AppendBytes( buffer := alloc.NewBuffer().Clear().AppendBytes(
0x05, // version 0x05, // version
@ -38,13 +37,13 @@ func TestAuthenticationRequestRead(t *testing.T) {
) )
request, _, err := ReadAuthentication(buffer) request, _, err := ReadAuthentication(buffer)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Byte(request.version).Named("Version").Equals(0x05) assert.Byte(request.version).Equals(0x05)
assert.Byte(request.nMethods).Named("#Methods").Equals(0x01) assert.Byte(request.nMethods).Equals(0x01)
assert.Byte(request.authMethods[0]).Named("Auth Method").Equals(0x02) assert.Byte(request.authMethods[0]).Equals(0x02)
} }
func TestAuthenticationResponseWrite(t *testing.T) { func TestAuthenticationResponseWrite(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
response := NewAuthenticationResponse(byte(0x05)) response := NewAuthenticationResponse(byte(0x05))
@ -54,7 +53,7 @@ func TestAuthenticationResponseWrite(t *testing.T) {
} }
func TestRequestRead(t *testing.T) { func TestRequestRead(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawRequest := []byte{ rawRequest := []byte{
0x05, // version 0x05, // version
@ -66,15 +65,15 @@ func TestRequestRead(t *testing.T) {
} }
request, err := ReadRequest(bytes.NewReader(rawRequest)) request, err := ReadRequest(bytes.NewReader(rawRequest))
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Byte(request.Version).Named("Version").Equals(0x05) assert.Byte(request.Version).Equals(0x05)
assert.Byte(request.Command).Named("Command").Equals(0x01) assert.Byte(request.Command).Equals(0x01)
assert.Byte(request.AddrType).Named("Address Type").Equals(0x01) assert.Byte(request.AddrType).Equals(0x01)
assert.Bytes(request.IPv4[:]).Named("IPv4").Equals([]byte{0x72, 0x72, 0x72, 0x72}) assert.Bytes(request.IPv4[:]).Equals([]byte{0x72, 0x72, 0x72, 0x72})
assert.Port(request.Port).Named("Port").Equals(v2net.Port(53)) assert.Port(request.Port).Equals(v2net.Port(53))
} }
func TestResponseWrite(t *testing.T) { func TestResponseWrite(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
response := Socks5Response{ response := Socks5Response{
socksVersion, socksVersion,
@ -97,11 +96,11 @@ func TestResponseWrite(t *testing.T) {
0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72,
byte(0x00), byte(0x035), byte(0x00), byte(0x035),
} }
assert.Bytes(buffer.Value).Named("raw response").Equals(expectedBytes) assert.Bytes(buffer.Value).Equals(expectedBytes)
} }
func TestSetIPv6(t *testing.T) { func TestSetIPv6(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
response := NewSocks5Response() response := NewSocks5Response()
response.SetIPv6([]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}) response.SetIPv6([]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15})
@ -114,7 +113,7 @@ func TestSetIPv6(t *testing.T) {
} }
func TestSetDomain(t *testing.T) { func TestSetDomain(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
response := NewSocks5Response() response := NewSocks5Response()
response.SetDomain("v2ray.com") response.SetDomain("v2ray.com")
@ -127,28 +126,28 @@ func TestSetDomain(t *testing.T) {
} }
func TestEmptyAuthRequest(t *testing.T) { func TestEmptyAuthRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
_, _, err := ReadAuthentication(alloc.NewBuffer().Clear()) _, _, err := ReadAuthentication(alloc.NewBuffer().Clear())
assert.Error(err).Equals(io.EOF) assert.Error(err).Equals(io.EOF)
} }
func TestSingleByteAuthRequest(t *testing.T) { func TestSingleByteAuthRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
_, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1))) _, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1)))
assert.Error(err).Equals(transport.ErrorCorruptedPacket) assert.Error(err).Equals(transport.ErrorCorruptedPacket)
} }
func TestZeroAuthenticationMethod(t *testing.T) { func TestZeroAuthenticationMethod(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewBuffer().Clear().AppendBytes(5, 0) buffer := alloc.NewBuffer().Clear().AppendBytes(5, 0)
_, _, err := ReadAuthentication(buffer) _, _, err := ReadAuthentication(buffer)
assert.Error(err).Equals(proxy.ErrorInvalidAuthentication) assert.Error(err).Equals(proxy.ErrorInvalidAuthentication)
} }
func TestWrongProtocolVersion(t *testing.T) { func TestWrongProtocolVersion(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewBuffer().Clear().AppendBytes(6, 1, 0) buffer := alloc.NewBuffer().Clear().AppendBytes(6, 1, 0)
_, _, err := ReadAuthentication(buffer) _, _, err := ReadAuthentication(buffer)
@ -156,14 +155,14 @@ func TestWrongProtocolVersion(t *testing.T) {
} }
func TestEmptyRequest(t *testing.T) { func TestEmptyRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
_, err := ReadRequest(alloc.NewBuffer().Clear()) _, err := ReadRequest(alloc.NewBuffer().Clear())
assert.Error(err).Equals(io.EOF) assert.Error(err).Equals(io.EOF)
} }
func TestIPv6Request(t *testing.T) { func TestIPv6Request(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
request, err := ReadRequest(alloc.NewBuffer().Clear().AppendBytes(5, 1, 0, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 8)) request, err := ReadRequest(alloc.NewBuffer().Clear().AppendBytes(5, 1, 0, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 8))
assert.Error(err).IsNil() assert.Error(err).IsNil()

View File

@ -4,13 +4,12 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/transport" "github.com/v2ray/v2ray-core/transport"
) )
func TestSingleByteUDPRequest(t *testing.T) { func TestSingleByteUDPRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
request, err := ReadUDPRequest(make([]byte, 1)) request, err := ReadUDPRequest(make([]byte, 1))
if request != nil { if request != nil {
@ -20,7 +19,7 @@ func TestSingleByteUDPRequest(t *testing.T) {
} }
func TestDomainAddressRequest(t *testing.T) { func TestDomainAddressRequest(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
payload := make([]byte, 0, 1024) payload := make([]byte, 0, 1024)
payload = append(payload, 0, 0, 1, AddrTypeDomain, byte(len("v2ray.com"))) payload = append(payload, 0, 0, 1, AddrTypeDomain, byte(len("v2ray.com")))
@ -32,7 +31,7 @@ func TestDomainAddressRequest(t *testing.T) {
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Byte(request.Fragment).Equals(1) assert.Byte(request.Fragment).Equals(1)
assert.String(request.Address).Equals("v2ray.com") assert.Address(request.Address).EqualsString("v2ray.com")
assert.Port(request.Port).Equals(v2net.Port(80)) assert.Port(request.Port).Equals(v2net.Port(80))
assert.Bytes(request.Data.Value).Equals([]byte("Actual payload")) assert.Bytes(request.Data.Value).Equals([]byte("Actual payload"))
} }

View File

@ -17,12 +17,11 @@ import (
proxytesting "github.com/v2ray/v2ray-core/proxy/testing" proxytesting "github.com/v2ray/v2ray-core/proxy/testing"
proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks" proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks"
"github.com/v2ray/v2ray-core/shell/point" "github.com/v2ray/v2ray-core/shell/point"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestSocksTcpConnect(t *testing.T) { func TestSocksTcpConnect(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
port := v2nettesting.PickPort() port := v2nettesting.PickPort()
connInput := []byte("The data to be returned to socks server.") connInput := []byte("The data to be returned to socks server.")
@ -82,11 +81,11 @@ func TestSocksTcpConnect(t *testing.T) {
assert.Bytes([]byte(data2Send)).Equals(connOutput.Bytes()) assert.Bytes([]byte(data2Send)).Equals(connOutput.Bytes())
assert.Bytes(dataReturned).Equals(connInput) assert.Bytes(dataReturned).Equals(connInput)
assert.StringLiteral(targetServer).Equals(och.Destination.NetAddr()) assert.String(targetServer).Equals(och.Destination.NetAddr())
} }
func TestSocksTcpConnectWithUserPass(t *testing.T) { func TestSocksTcpConnectWithUserPass(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
port := v2nettesting.PickPort() port := v2nettesting.PickPort()
connInput := []byte("The data to be returned to socks server.") connInput := []byte("The data to be returned to socks server.")
@ -149,11 +148,11 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
assert.Bytes([]byte(data2Send)).Equals(connOutput.Bytes()) assert.Bytes([]byte(data2Send)).Equals(connOutput.Bytes())
assert.Bytes(dataReturned).Equals(connInput) assert.Bytes(dataReturned).Equals(connInput)
assert.StringLiteral(targetServer).Equals(och.Destination.NetAddr()) assert.String(targetServer).Equals(och.Destination.NetAddr())
} }
func TestSocksTcpConnectWithWrongUserPass(t *testing.T) { func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
port := v2nettesting.PickPort() port := v2nettesting.PickPort()
connInput := []byte("The data to be returned to socks server.") connInput := []byte("The data to be returned to socks server.")
@ -206,7 +205,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
} }
func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) { func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
port := v2nettesting.PickPort() port := v2nettesting.PickPort()
connInput := []byte("The data to be returned to socks server.") connInput := []byte("The data to be returned to socks server.")

View File

@ -3,7 +3,6 @@ package inbound
import ( import (
"github.com/v2ray/v2ray-core/common/log" "github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/serial"
) )
func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader) protocol.ResponseCommand { func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader) protocol.ResponseCommand {
@ -23,7 +22,7 @@ func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader
return &protocol.CommandSwitchAccount{ return &protocol.CommandSwitchAccount{
Port: inboundHandler.Port(), Port: inboundHandler.Port(),
ID: user.ID.UUID(), ID: user.ID.UUID(),
AlterIds: serial.Uint16Literal(len(user.AlterIDs)), AlterIds: uint16(len(user.AlterIDs)),
Level: user.Level, Level: user.Level,
ValidMin: byte(availableMin), ValidMin: byte(availableMin),
} }

View File

@ -9,12 +9,11 @@ import (
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
. "github.com/v2ray/v2ray-core/proxy/vmess/io" . "github.com/v2ray/v2ray-core/proxy/vmess/io"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestAuthenticate(t *testing.T) { func TestAuthenticate(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
buffer := alloc.NewBuffer().Clear() buffer := alloc.NewBuffer().Clear()
buffer.AppendBytes(1, 2, 3, 4) buffer.AppendBytes(1, 2, 3, 4)
@ -27,7 +26,7 @@ func TestAuthenticate(t *testing.T) {
} }
func TestSingleIO(t *testing.T) { func TestSingleIO(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
content := bytes.NewBuffer(make([]byte, 0, 1024*1024)) content := bytes.NewBuffer(make([]byte, 0, 1024*1024))
@ -42,7 +41,7 @@ func TestSingleIO(t *testing.T) {
} }
func TestLargeIO(t *testing.T) { func TestLargeIO(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
content := make([]byte, 1024*1024) content := make([]byte, 1024*1024)
rand.Read(content) rand.Read(content)

View File

@ -35,5 +35,5 @@ func Authenticate(buffer *alloc.Buffer) {
buffer.SliceBack(4) buffer.SliceBack(4)
fnvHash.Sum(buffer.Value[:0]) fnvHash.Sum(buffer.Value[:0])
buffer.Prepend(serial.Uint16Literal(uint16(buffer.Len())).Bytes()) buffer.Prepend(serial.Uint16ToBytes(uint16(buffer.Len())))
} }

View File

@ -7,7 +7,7 @@ import (
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) { func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
primary := protocol.NewID(cmd.ID) primary := protocol.NewID(cmd.ID)
alters := protocol.NewAlterIDs(primary, cmd.AlterIds.Value()) alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
user := protocol.NewUser(primary, alters, cmd.Level, "") user := protocol.NewUser(primary, alters, cmd.Level, "")
dest := v2net.TCPDestination(cmd.Host, cmd.Port) dest := v2net.TCPDestination(cmd.Host, cmd.Port)
this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin) this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)

View File

@ -7,12 +7,11 @@ import (
"testing" "testing"
. "github.com/v2ray/v2ray-core/proxy/vmess/outbound" . "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestConfigTargetParsing(t *testing.T) { func TestConfigTargetParsing(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := `{ rawJson := `{
"address": "127.0.0.1", "address": "127.0.0.1",
@ -29,7 +28,7 @@ func TestConfigTargetParsing(t *testing.T) {
receiver := new(Receiver) receiver := new(Receiver)
err := json.Unmarshal([]byte(rawJson), &receiver) err := json.Unmarshal([]byte(rawJson), &receiver)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.String(receiver.Destination).Equals("tcp:127.0.0.1:80") assert.Destination(receiver.Destination).EqualsString("tcp:127.0.0.1:80")
assert.Int(len(receiver.Accounts)).Equals(1) assert.Int(len(receiver.Accounts)).Equals(1)
assert.String(receiver.Accounts[0].ID).Equals("e641f5ad-9397-41e3-bf1a-e8740dfed019") assert.String(receiver.Accounts[0].ID.String()).Equals("e641f5ad-9397-41e3-bf1a-e8740dfed019")
} }

View File

@ -7,12 +7,11 @@ import (
"github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/uuid" "github.com/v2ray/v2ray-core/common/uuid"
. "github.com/v2ray/v2ray-core/proxy/vmess/outbound" . "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestReceiverUser(t *testing.T) { func TestReceiverUser(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
id := protocol.NewID(uuid.New()) id := protocol.NewID(uuid.New())
alters := protocol.NewAlterIDs(id, 100) alters := protocol.NewAlterIDs(id, 100)

View File

@ -17,12 +17,11 @@ import (
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound" _ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound" _ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
"github.com/v2ray/v2ray-core/shell/point" "github.com/v2ray/v2ray-core/shell/point"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestVMessInAndOut(t *testing.T) { func TestVMessInAndOut(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
id, err := uuid.ParseString("ad937d9d-6e23-4a5a-ba23-bce5092a7c51") id, err := uuid.ParseString("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
assert.Error(err).IsNil() assert.Error(err).IsNil()

View File

@ -11,12 +11,11 @@ import (
_ "github.com/v2ray/v2ray-core/app/router/rules" _ "github.com/v2ray/v2ray-core/app/router/rules"
. "github.com/v2ray/v2ray-core/shell/point" . "github.com/v2ray/v2ray-core/shell/point"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestClientSampleConfig(t *testing.T) { func TestClientSampleConfig(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
GOPATH := os.Getenv("GOPATH") GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config") baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
@ -28,15 +27,15 @@ func TestClientSampleConfig(t *testing.T) {
assert.Pointer(pointConfig.InboundConfig).IsNotNil() assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil() assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.StringLiteral(pointConfig.InboundConfig.Protocol).Equals("socks") assert.String(pointConfig.InboundConfig.Protocol).Equals("socks")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil() assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.StringLiteral(pointConfig.OutboundConfig.Protocol).Equals("vmess") assert.String(pointConfig.OutboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil() assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
} }
func TestServerSampleConfig(t *testing.T) { func TestServerSampleConfig(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
GOPATH := os.Getenv("GOPATH") GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config") baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
@ -48,15 +47,15 @@ func TestServerSampleConfig(t *testing.T) {
assert.Pointer(pointConfig.InboundConfig).IsNotNil() assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil() assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.StringLiteral(pointConfig.InboundConfig.Protocol).Equals("vmess") assert.String(pointConfig.InboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil() assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.StringLiteral(pointConfig.OutboundConfig.Protocol).Equals("freedom") assert.String(pointConfig.OutboundConfig.Protocol).Equals("freedom")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil() assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
} }
func TestDefaultValueOfRandomAllocation(t *testing.T) { func TestDefaultValueOfRandomAllocation(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rawJson := `{ rawJson := `{
"protocol": "vmess", "protocol": "vmess",
@ -70,7 +69,7 @@ func TestDefaultValueOfRandomAllocation(t *testing.T) {
inboundDetourConfig := new(InboundDetourConfig) inboundDetourConfig := new(InboundDetourConfig)
err := json.Unmarshal([]byte(rawJson), inboundDetourConfig) err := json.Unmarshal([]byte(rawJson), inboundDetourConfig)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom) assert.String(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom)
assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3) assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3)
assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5) assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5)
} }

View File

@ -2,11 +2,16 @@ package assert
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
) )
func Address(value v2net.Address) *AddressSubject { func (this *Assert) Address(value v2net.Address) *AddressSubject {
return &AddressSubject{value: value} return &AddressSubject{
Subject: Subject{
disp: value.String(),
a: this,
},
value: value,
}
} }
type AddressSubject struct { type AddressSubject struct {
@ -14,53 +19,62 @@ type AddressSubject struct {
value v2net.Address value v2net.Address
} }
func (subject *AddressSubject) Named(name string) *AddressSubject { func (subject *AddressSubject) NotEquals(another v2net.Address) {
subject.Subject.Named(name) if subject.value.Equals(another) {
return subject subject.Fail("not equals to", another.String())
} }
func (subject *AddressSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
} }
func (subject *AddressSubject) Equals(another v2net.Address) { func (subject *AddressSubject) Equals(another v2net.Address) {
if !subject.value.Equals(another) { if !subject.value.Equals(another) {
subject.Fail(subject.DisplayString(), "equals to", another) subject.Fail("equals to", another.String())
}
}
func (subject *AddressSubject) NotEqualsString(another string) {
if subject.value.String() == another {
subject.Fail("not equals to string", another)
}
}
func (subject *AddressSubject) EqualsString(another string) {
if subject.value.String() != another {
subject.Fail("equals to string", another)
} }
} }
func (subject *AddressSubject) IsIPv4() { func (subject *AddressSubject) IsIPv4() {
if !subject.value.IsIPv4() { if !subject.value.IsIPv4() {
subject.Fail(subject.DisplayString(), "is", serial.StringT("an IPv4 address")) subject.Fail("is", "an IPv4 address")
} }
} }
func (subject *AddressSubject) IsNotIPv4() { func (subject *AddressSubject) IsNotIPv4() {
if subject.value.IsIPv4() { if subject.value.IsIPv4() {
subject.Fail(subject.DisplayString(), "is not", serial.StringT("an IPv4 address")) subject.Fail("is not", "an IPv4 address")
} }
} }
func (subject *AddressSubject) IsIPv6() { func (subject *AddressSubject) IsIPv6() {
if !subject.value.IsIPv6() { if !subject.value.IsIPv6() {
subject.Fail(subject.DisplayString(), "is", serial.StringT("an IPv6 address")) subject.Fail("is", "an IPv6 address")
} }
} }
func (subject *AddressSubject) IsNotIPv6() { func (subject *AddressSubject) IsNotIPv6() {
if subject.value.IsIPv6() { if subject.value.IsIPv6() {
subject.Fail(subject.DisplayString(), "is not", serial.StringT("an IPv6 address")) subject.Fail("is not", "an IPv6 address")
} }
} }
func (subject *AddressSubject) IsDomain() { func (subject *AddressSubject) IsDomain() {
if !subject.value.IsDomain() { if !subject.value.IsDomain() {
subject.Fail(subject.DisplayString(), "is", serial.StringT("a domain address")) subject.Fail("is", "a domain address")
} }
} }
func (subject *AddressSubject) IsNotDomain() { func (subject *AddressSubject) IsNotDomain() {
if subject.value.IsDomain() { if subject.value.IsDomain() {
subject.Fail(subject.DisplayString(), "is not", serial.StringT("a domain address")) subject.Fail("is not", "a domain address")
} }
} }

View File

@ -1,4 +1,4 @@
package unit package assert
import ( import (
"bytes" "bytes"
@ -8,10 +8,19 @@ import (
"testing" "testing"
) )
var tGlobal *testing.T func On(t *testing.T) *Assert {
return &Assert{
t: t,
}
}
func Current(t *testing.T) { type Assert struct {
tGlobal = t t *testing.T
}
func (this *Assert) Fail(message string) {
fmt.Println(decorate(message))
this.t.Fail()
} }
func getCaller() (string, int) { func getCaller() (string, int) {
@ -59,8 +68,3 @@ func decorate(s string) string {
buf.WriteByte('\n') buf.WriteByte('\n')
return buf.String() return buf.String()
} }
func Fail(message string) {
fmt.Println(decorate(message))
tGlobal.Fail()
}

42
testing/assert/bool.go Normal file
View File

@ -0,0 +1,42 @@
package assert
import (
"strconv"
)
// Assert on a boolean variable.
func (this *Assert) Bool(value bool) *BoolSubject {
return &BoolSubject{
Subject: Subject{
disp: strconv.FormatBool(value),
a: this,
},
value: value,
}
}
type BoolSubject struct {
Subject
value bool
}
// to be equal to another boolean variable.
func (subject *BoolSubject) Equals(expectation bool) {
if subject.value != expectation {
subject.Fail("is equal to", strconv.FormatBool(expectation))
}
}
// to be true.
func (subject *BoolSubject) IsTrue() {
if subject.value != true {
subject.Fail("is", "True")
}
}
// to be false.
func (subject *BoolSubject) IsFalse() {
if subject.value != false {
subject.Fail("is", "False")
}
}

View File

@ -1,49 +0,0 @@
package assert
import (
"strconv"
)
// Assert on a boolean variable.
func Bool(value bool) *BoolSubject {
return &BoolSubject{value: value}
}
type BoolSubject struct {
Subject
value bool
}
func (subject *BoolSubject) Named(name string) *BoolSubject {
subject.Subject.Named(name)
return subject
}
func (subject *BoolSubject) Fail(verb string, other bool) {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.FormatBool(other) + ">.")
}
func (subject *BoolSubject) DisplayString() string {
return subject.Subject.DisplayString(strconv.FormatBool(subject.value))
}
// to be equal to another boolean variable.
func (subject *BoolSubject) Equals(expectation bool) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
// to be true.
func (subject *BoolSubject) IsTrue() {
if subject.value != true {
subject.Fail("is", true)
}
}
// to be false.
func (subject *BoolSubject) IsFalse() {
if subject.value != false {
subject.Fail("is", false)
}
}

38
testing/assert/byte.go Normal file
View File

@ -0,0 +1,38 @@
package assert
import (
"github.com/v2ray/v2ray-core/common/serial"
)
func (this *Assert) Byte(value byte) *ByteSubject {
return &ByteSubject{
Subject: Subject{
disp: serial.ByteToHexString(value),
a: this,
},
value: value,
}
}
type ByteSubject struct {
Subject
value byte
}
func (subject *ByteSubject) Equals(expectation byte) {
if subject.value != expectation {
subject.Fail("is equal to", serial.ByteToHexString(expectation))
}
}
func (subject *ByteSubject) GreaterThan(expectation byte) {
if subject.value <= expectation {
subject.Fail("is greater than", serial.ByteToHexString(expectation))
}
}
func (subject *ByteSubject) LessThan(expectation byte) {
if subject.value >= expectation {
subject.Fail("is less than", serial.ByteToHexString(expectation))
}
}

34
testing/assert/bytes.go Normal file
View File

@ -0,0 +1,34 @@
package assert
import (
"bytes"
"github.com/v2ray/v2ray-core/common/serial"
)
func (this *Assert) Bytes(value []byte) *BytesSubject {
return &BytesSubject{
Subject: Subject{
disp: serial.BytesToHexString(value),
a: this,
},
value: value,
}
}
type BytesSubject struct {
Subject
value []byte
}
func (subject *BytesSubject) Equals(expectation []byte) {
if !bytes.Equal(subject.value, expectation) {
subject.Fail("is equal to", serial.BytesToHexString(expectation))
}
}
func (subject *BytesSubject) NotEquals(expectation []byte) {
if bytes.Equal(subject.value, expectation) {
subject.Fail("is not equal to", serial.BytesToHexString(expectation))
}
}

View File

@ -1,41 +0,0 @@
package assert
import (
"bytes"
"fmt"
)
func Bytes(value []byte) *BytesSubject {
return &BytesSubject{value: value}
}
type BytesSubject struct {
Subject
value []byte
}
func (subject *BytesSubject) Named(name string) *BytesSubject {
subject.Subject.Named(name)
return subject
}
func (subject *BytesSubject) Fail(verb string, other []byte) {
otherString := fmt.Sprintf("%v", other)
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + otherString + ">.")
}
func (subject *BytesSubject) DisplayString() string {
return subject.Subject.DisplayString(fmt.Sprintf("%v", subject.value))
}
func (subject *BytesSubject) Equals(expectation []byte) {
if !bytes.Equal(subject.value, expectation) {
subject.Fail("is equal to", expectation)
}
}
func (subject *BytesSubject) NotEquals(expectation []byte) {
if bytes.Equal(subject.value, expectation) {
subject.Fail("is not equal to", expectation)
}
}

View File

@ -1,45 +0,0 @@
package assert
import (
"strconv"
)
func Byte(value byte) *ByteSubject {
return &ByteSubject{value: value}
}
type ByteSubject struct {
Subject
value byte
}
func (subject *ByteSubject) Named(name string) *ByteSubject {
subject.Subject.Named(name)
return subject
}
func (subject *ByteSubject) Fail(verb string, other byte) {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.Itoa(int(other)) + ">.")
}
func (subject *ByteSubject) DisplayString() string {
return subject.Subject.DisplayString(strconv.Itoa(int(subject.value)))
}
func (subject *ByteSubject) Equals(expectation byte) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
func (subject *ByteSubject) GreaterThan(expectation byte) {
if subject.value <= expectation {
subject.Fail("is greater than", expectation)
}
}
func (subject *ByteSubject) LessThan(expectation byte) {
if subject.value >= expectation {
subject.Fail("is less than", expectation)
}
}

View File

@ -2,11 +2,16 @@ package assert
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
) )
func Destination(value v2net.Destination) *DestinationSubject { func (this *Assert) Destination(value v2net.Destination) *DestinationSubject {
return &DestinationSubject{value: value} return &DestinationSubject{
Subject: Subject{
disp: value.String(),
a: this,
},
value: value,
}
} }
type DestinationSubject struct { type DestinationSubject struct {
@ -14,35 +19,40 @@ type DestinationSubject struct {
value v2net.Destination 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() { func (this *DestinationSubject) IsTCP() {
if !this.value.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() { func (this *DestinationSubject) IsNotTCP() {
if this.value.IsTCP() { 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() { func (this *DestinationSubject) IsUDP() {
if !this.value.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() { func (this *DestinationSubject) IsNotUDP() {
if this.value.IsUDP() { 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())
}

38
testing/assert/error.go Normal file
View File

@ -0,0 +1,38 @@
package assert
func (this *Assert) Error(value error) *ErrorSubject {
valueStr := ""
if value != nil {
valueStr = value.Error()
}
return &ErrorSubject{
Subject: Subject{
a: this,
disp: valueStr,
},
value: value,
}
}
type ErrorSubject struct {
Subject
value error
}
func (subject *ErrorSubject) Equals(expectation error) {
if subject.value != expectation {
subject.Fail("is equal to", expectation.Error())
}
}
func (subject *ErrorSubject) IsNil() {
if subject.value != nil {
subject.Fail("is", "nil")
}
}
func (subject *ErrorSubject) IsNotNil() {
if subject.value == nil {
subject.Fail("is not", "nil")
}
}

View File

@ -1,41 +0,0 @@
package assert
func Error(value error) *ErrorSubject {
return &ErrorSubject{value: value}
}
type ErrorSubject struct {
Subject
value error
}
func (subject *ErrorSubject) Named(name string) *ErrorSubject {
subject.Subject.Named(name)
return subject
}
func (subject *ErrorSubject) Fail(verb string, other error) {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other.Error() + ">.")
}
func (subject *ErrorSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.Error())
}
func (subject *ErrorSubject) Equals(expectation error) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
func (subject *ErrorSubject) IsNil() {
if subject.value != nil {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
}
}
func (subject *ErrorSubject) IsNotNil() {
if subject.value == nil {
subject.FailWithMessage("Not true that the error is not nil.")
}
}

44
testing/assert/int64.go Normal file
View File

@ -0,0 +1,44 @@
package assert
import (
"github.com/v2ray/v2ray-core/common/serial"
)
func (this *Assert) Int64(value int64) *Int64Subject {
return &Int64Subject{
Subject: Subject{
a: this,
disp: serial.Int64ToString(value),
},
value: value,
}
}
type Int64Subject struct {
Subject
value int64
}
func (subject *Int64Subject) Equals(expectation int64) {
if subject.value != expectation {
subject.Fail("is equal to", serial.Int64ToString(expectation))
}
}
func (subject *Int64Subject) GreaterThan(expectation int64) {
if subject.value <= expectation {
subject.Fail("is greater than", serial.Int64ToString(expectation))
}
}
func (subject *Int64Subject) AtMost(expectation int64) {
if subject.value > expectation {
subject.Fail("is at most", serial.Int64ToString(expectation))
}
}
func (subject *Int64Subject) AtLeast(expectation int64) {
if subject.value < expectation {
subject.Fail("is at least", serial.Int64ToString(expectation))
}
}

View File

@ -1,51 +0,0 @@
package assert
import (
"strconv"
)
func Int64(value int64) *Int64Subject {
return &Int64Subject{value: value}
}
type Int64Subject struct {
Subject
value int64
}
func (subject *Int64Subject) Named(name string) *Int64Subject {
subject.Subject.Named(name)
return subject
}
func (subject *Int64Subject) Fail(verb string, other int64) {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.FormatInt(other, 10) + ">.")
}
func (subject *Int64Subject) DisplayString() string {
return subject.Subject.DisplayString(strconv.FormatInt(subject.value, 10))
}
func (subject *Int64Subject) Equals(expectation int64) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
func (subject *Int64Subject) GreaterThan(expectation int64) {
if subject.value <= expectation {
subject.Fail("is greater than", expectation)
}
}
func (subject *Int64Subject) AtMost(expectation int64) {
if subject.value > expectation {
subject.Fail("is at most", expectation)
}
}
func (subject *Int64Subject) AtLeast(expectation int64) {
if subject.value < expectation {
subject.Fail("is at least", expectation)
}
}

View File

@ -4,38 +4,35 @@ import (
"github.com/v2ray/v2ray-core/common/serial" "github.com/v2ray/v2ray-core/common/serial"
) )
func Int(value int) *IntSubject { func (this *Assert) Int(value int) *IntSubject {
return &IntSubject{value: serial.IntLiteral(value)} return &IntSubject{
Subject: Subject{
a: this,
disp: serial.IntToString(value),
},
value: value,
}
} }
type IntSubject struct { type IntSubject struct {
Subject Subject
value serial.IntLiteral value int
}
func (subject *IntSubject) Named(name string) *IntSubject {
subject.Subject.Named(name)
return subject
}
func (subject *IntSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
} }
func (subject *IntSubject) Equals(expectation int) { func (subject *IntSubject) Equals(expectation int) {
if subject.value.Value() != expectation { if subject.value != expectation {
subject.Fail(subject.DisplayString(), "is equal to", serial.IntLiteral(expectation)) subject.Fail("is equal to", serial.IntToString(expectation))
} }
} }
func (subject *IntSubject) GreaterThan(expectation int) { func (subject *IntSubject) GreaterThan(expectation int) {
if subject.value.Value() <= expectation { if subject.value <= expectation {
subject.Fail(subject.DisplayString(), "is greater than", serial.IntLiteral(expectation)) subject.Fail("is greater than", serial.IntToString(expectation))
} }
} }
func (subject *IntSubject) LessThan(expectation int) { func (subject *IntSubject) LessThan(expectation int) {
if subject.value.Value() >= expectation { if subject.value >= expectation {
subject.Fail(subject.DisplayString(), "is less than", serial.IntLiteral(expectation)) subject.Fail("is less than", serial.IntToString(expectation))
} }
} }

View File

@ -3,12 +3,16 @@ package assert
import ( import (
"bytes" "bytes"
"net" "net"
"github.com/v2ray/v2ray-core/common/serial"
) )
func IP(value net.IP) *IPSubject { func (this *Assert) IP(value net.IP) *IPSubject {
return &IPSubject{value: value} return &IPSubject{
Subject: Subject{
a: this,
disp: value.String(),
},
value: value,
}
} }
type IPSubject struct { type IPSubject struct {
@ -16,23 +20,14 @@ type IPSubject struct {
value net.IP value net.IP
} }
func (subject *IPSubject) Named(name string) *IPSubject {
subject.Subject.Named(name)
return subject
}
func (subject *IPSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
}
func (subject *IPSubject) IsNil() { func (subject *IPSubject) IsNil() {
if subject.value != nil { if subject.value != nil {
subject.Fail(subject.DisplayString(), "is", serial.StringT("nil")) subject.Fail("is", "nil")
} }
} }
func (subject *IPSubject) Equals(ip net.IP) { func (subject *IPSubject) Equals(ip net.IP) {
if !bytes.Equal([]byte(subject.value), []byte(ip)) { if !bytes.Equal([]byte(subject.value), []byte(ip)) {
subject.Fail(subject.DisplayString(), "equals to", ip) subject.Fail("equals to", ip.String())
} }
} }

38
testing/assert/pointer.go Normal file
View File

@ -0,0 +1,38 @@
package assert
import (
"github.com/v2ray/v2ray-core/common/serial"
)
func (this *Assert) Pointer(value interface{}) *PointerSubject {
return &PointerSubject{
Subject: Subject{
a: this,
disp: serial.PointerToString(value),
},
value: value,
}
}
type PointerSubject struct {
Subject
value interface{}
}
func (subject *PointerSubject) Equals(expectation interface{}) {
if subject.value != expectation {
subject.Fail("is equal to", serial.PointerToString(expectation))
}
}
func (subject *PointerSubject) IsNil() {
if subject.value != nil {
subject.Fail("is", "nil")
}
}
func (subject *PointerSubject) IsNotNil() {
if subject.value == nil {
subject.Fail("is not", "nil")
}
}

View File

@ -1,45 +0,0 @@
package assert
import (
"fmt"
)
func Pointer(value interface{}) *PointerSubject {
return &PointerSubject{value: value}
}
type PointerSubject struct {
Subject
value interface{}
}
func (subject *PointerSubject) Named(name string) *PointerSubject {
subject.Subject.Named(name)
return subject
}
func (subject *PointerSubject) Fail(verb string, other interface{}) {
subject.FailWithMessage(fmt.Sprintf("Not true that %s %s <%v>.", subject.DisplayString(), verb, other))
}
func (subject *PointerSubject) DisplayString() string {
return subject.Subject.DisplayString(fmt.Sprintf("%v", subject.value))
}
func (subject *PointerSubject) Equals(expectation interface{}) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
func (subject *PointerSubject) IsNil() {
if subject.value != nil {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
}
}
func (subject *PointerSubject) IsNotNil() {
if subject.value == nil {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is not nil.")
}
}

View File

@ -2,11 +2,16 @@ package assert
import ( import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
) )
func Port(value v2net.Port) *PortSubject { func (this *Assert) Port(value v2net.Port) *PortSubject {
return &PortSubject{value: value} return &PortSubject{
Subject: Subject{
a: this,
disp: value.String(),
},
value: value,
}
} }
type PortSubject struct { type PortSubject struct {
@ -14,35 +19,26 @@ type PortSubject struct {
value v2net.Port value v2net.Port
} }
func (subject *PortSubject) Named(name string) *PortSubject {
subject.Subject.Named(name)
return subject
}
func (subject *PortSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
}
func (subject *PortSubject) Equals(expectation v2net.Port) { func (subject *PortSubject) Equals(expectation v2net.Port) {
if subject.value.Value() != expectation.Value() { if subject.value.Value() != expectation.Value() {
subject.Fail(subject.DisplayString(), "is equal to", expectation) subject.Fail("is equal to", expectation.String())
} }
} }
func (subject *PortSubject) GreaterThan(expectation v2net.Port) { func (subject *PortSubject) GreaterThan(expectation v2net.Port) {
if subject.value.Value() <= expectation.Value() { if subject.value.Value() <= expectation.Value() {
subject.Fail(subject.DisplayString(), "is greater than", expectation) subject.Fail("is greater than", expectation.String())
} }
} }
func (subject *PortSubject) LessThan(expectation v2net.Port) { func (subject *PortSubject) LessThan(expectation v2net.Port) {
if subject.value.Value() >= expectation.Value() { if subject.value.Value() >= expectation.Value() {
subject.Fail(subject.DisplayString(), "is less than", expectation) subject.Fail("is less than", expectation.String())
} }
} }
func (subject *PortSubject) IsValid() { func (subject *PortSubject) IsValid() {
if subject.value == 0 { if subject.value == 0 {
subject.Fail(subject.DisplayString(), "is", serial.StringT("a valid port")) subject.Fail("is", "a valid port")
} }
} }

44
testing/assert/string.go Normal file
View File

@ -0,0 +1,44 @@
package assert
import (
"strings"
)
func (this *Assert) String(value string) *StringSubject {
return &StringSubject{
Subject: Subject{
a: this,
disp: value,
},
value: value,
}
}
type StringSubject struct {
Subject
value string
}
func (subject *StringSubject) Equals(expectation string) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
func (subject *StringSubject) NotEquals(expectation string) {
if subject.value == expectation {
subject.Fail("is not equal to ", expectation)
}
}
func (subject *StringSubject) Contains(substring string) {
if !strings.Contains(subject.value, substring) {
subject.Fail("contains", substring)
}
}
func (subject *StringSubject) NotContains(substring string) {
if strings.Contains(subject.value, substring) {
subject.Fail("doesn't contain", substring)
}
}

View File

@ -1,53 +0,0 @@
package assert
import (
"strings"
"github.com/v2ray/v2ray-core/common/serial"
)
func StringLiteral(value string) *StringSubject {
return String(serial.StringT((value)))
}
func String(value serial.String) *StringSubject {
return &StringSubject{value: value}
}
type StringSubject struct {
Subject
value serial.String
}
func (subject *StringSubject) Named(name string) *StringSubject {
subject.Subject.Named(name)
return subject
}
func (subject *StringSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
}
func (subject *StringSubject) Equals(expectation string) {
if subject.value.String() != expectation {
subject.Fail(subject.DisplayString(), "is equal to", serial.StringT(expectation))
}
}
func (subject *StringSubject) NotEquals(expectation string) {
if subject.value.String() == expectation {
subject.Fail(subject.DisplayString(), "is not equal to ", serial.StringT(expectation))
}
}
func (subject *StringSubject) Contains(substring serial.String) {
if !strings.Contains(subject.value.String(), substring.String()) {
subject.Fail(subject.DisplayString(), "contains", substring)
}
}
func (subject *StringSubject) NotContains(substring serial.String) {
if strings.Contains(subject.value.String(), substring.String()) {
subject.Fail(subject.DisplayString(), "doesn't contain", substring)
}
}

View File

@ -1,38 +1,22 @@
package assert package assert
import (
"github.com/v2ray/v2ray-core/common/serial"
v2testing "github.com/v2ray/v2ray-core/testing"
)
type Subject struct { type Subject struct {
name string disp string
a *Assert
} }
func NewSubject() *Subject { func (subject *Subject) Fail(verb string, other string) {
return &Subject{ subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other + ">.")
name: "",
}
}
func (subject *Subject) Fail(displayString string, verb string, other serial.String) {
subject.FailWithMessage("Not true that " + displayString + " " + verb + " <" + other.String() + ">.")
} }
func (subject *Subject) FailWithMessage(message string) { func (subject *Subject) FailWithMessage(message string) {
v2testing.Fail(message) subject.a.Fail(message)
} }
func (subject *Subject) Named(name string) { func (subject *Subject) DisplayString() string {
subject.name = name value := subject.disp
}
func (subject *Subject) DisplayString(value string) string {
if len(value) == 0 { if len(value) == 0 {
value = "unknown" value = "unknown"
} }
if len(subject.name) == 0 { return "<" + value + ">"
return "<" + value + ">"
}
return subject.name + "(<" + value + ">)"
} }

50
testing/assert/uint16.go Normal file
View File

@ -0,0 +1,50 @@
package assert
import (
"github.com/v2ray/v2ray-core/common/serial"
)
func (this *Assert) Uint16(value uint16) *Uint16Subject {
return &Uint16Subject{
Subject: Subject{
a: this,
disp: serial.Uint16ToString(value),
},
value: value,
}
}
type Uint16Subject struct {
Subject
value uint16
}
func (subject *Uint16Subject) Equals(expectation uint16) {
if subject.value != expectation {
subject.Fail("is equal to", serial.Uint16ToString(expectation))
}
}
func (subject *Uint16Subject) GreaterThan(expectation uint16) {
if subject.value <= expectation {
subject.Fail("is greater than", serial.Uint16ToString(expectation))
}
}
func (subject *Uint16Subject) LessThan(expectation uint16) {
if subject.value >= expectation {
subject.Fail("is less than", serial.Uint16ToString(expectation))
}
}
func (subject *Uint16Subject) IsPositive() {
if subject.value <= 0 {
subject.Fail("is", "positive")
}
}
func (subject *Uint16Subject) IsNegative() {
if subject.value >= 0 {
subject.Fail("is not", "negative")
}
}

View File

@ -1,47 +0,0 @@
package assert
import (
"github.com/v2ray/v2ray-core/common/serial"
)
func Uint16(value uint16) *Uint16Subject {
return &Uint16Subject{value: serial.Uint16Literal(value)}
}
type Uint16Subject struct {
Subject
value serial.Uint16Literal
}
func (subject *Uint16Subject) Named(name string) *Uint16Subject {
subject.Subject.Named(name)
return subject
}
func (subject *Uint16Subject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
}
func (subject *Uint16Subject) Equals(expectation uint16) {
if subject.value.Value() != expectation {
subject.Fail(subject.DisplayString(), "is equal to", serial.Uint16Literal(expectation))
}
}
func (subject *Uint16Subject) GreaterThan(expectation uint16) {
if subject.value.Value() <= expectation {
subject.Fail(subject.DisplayString(), "is greater than", serial.Uint16Literal(expectation))
}
}
func (subject *Uint16Subject) LessThan(expectation uint16) {
if subject.value.Value() >= expectation {
subject.Fail(subject.DisplayString(), "is less than", serial.Uint16Literal(expectation))
}
}
func (subject *Uint16Subject) Positive() {
if subject.value.Value() <= 0 {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is positive.")
}
}

View File

@ -5,13 +5,12 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
) )
func TestDokodemoTCP(t *testing.T) { func TestDokodemoTCP(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
Port: v2net.Port(50016), Port: v2net.Port(50016),
@ -47,7 +46,7 @@ func TestDokodemoTCP(t *testing.T) {
response := make([]byte, 1024) response := make([]byte, 1024)
nBytes, err = conn.Read(response) nBytes, err = conn.Read(response)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response[:nBytes])) assert.String("Processed: " + payload).Equals(string(response[:nBytes]))
conn.Close() conn.Close()
} }

View File

@ -7,13 +7,12 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
) )
func TestDynamicVMess(t *testing.T) { func TestDynamicVMess(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
Port: v2net.Port(50032), Port: v2net.Port(50032),
@ -47,7 +46,7 @@ func TestDynamicVMess(t *testing.T) {
response := bytes.NewBuffer(nil) response := bytes.NewBuffer(nil)
_, err = io.Copy(response, conn) _, err = io.Copy(response, conn)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response.Bytes())) assert.String("Processed: " + payload).Equals(string(response.Bytes()))
conn.Close() conn.Close()
} }

View File

@ -7,13 +7,12 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
v2http "github.com/v2ray/v2ray-core/testing/servers/http" v2http "github.com/v2ray/v2ray-core/testing/servers/http"
) )
func TestHttpProxy(t *testing.T) { func TestHttpProxy(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
httpServer := &v2http.Server{ httpServer := &v2http.Server{
Port: v2net.Port(50042), Port: v2net.Port(50042),
@ -41,7 +40,7 @@ func TestHttpProxy(t *testing.T) {
content, err := ioutil.ReadAll(resp.Body) content, err := ioutil.ReadAll(resp.Body)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral(string(content)).Equals("Home") assert.String(string(content)).Equals("Home")
CloseAllServers() CloseAllServers()
} }

View File

@ -5,13 +5,12 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
) )
func TestRouter(t *testing.T) { func TestRouter(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
Port: v2net.Port(50024), Port: v2net.Port(50024),
@ -56,7 +55,7 @@ func TestRouter(t *testing.T) {
response := make([]byte, 1024) response := make([]byte, 1024)
nBytes, err = conn.Read(response) nBytes, err = conn.Read(response)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response[:nBytes])) assert.String("Processed: " + payload).Equals(string(response[:nBytes]))
conn.Close() conn.Close()
conn, err = net.DialTCP("tcp", nil, &net.TCPAddr{ conn, err = net.DialTCP("tcp", nil, &net.TCPAddr{

View File

@ -5,7 +5,6 @@ import (
"testing" "testing"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
@ -13,7 +12,7 @@ import (
) )
func TestShadowsocksTCP(t *testing.T) { func TestShadowsocksTCP(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
Port: v2net.Port(50052), Port: v2net.Port(50052),
@ -47,7 +46,7 @@ func TestShadowsocksTCP(t *testing.T) {
response := make([]byte, 1024) response := make([]byte, 1024)
nBytes, err = conn.Read(response) nBytes, err = conn.Read(response)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response[:nBytes])) assert.String("Processed: " + payload).Equals(string(response[:nBytes]))
conn.Close() conn.Close()
cipher, err = ssclient.NewCipher("aes-128-cfb", "v2ray-another") cipher, err = ssclient.NewCipher("aes-128-cfb", "v2ray-another")
@ -66,7 +65,7 @@ func TestShadowsocksTCP(t *testing.T) {
response = make([]byte, 1024) response = make([]byte, 1024)
nBytes, err = conn.Read(response) nBytes, err = conn.Read(response)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response[:nBytes])) assert.String("Processed: " + payload).Equals(string(response[:nBytes]))
conn.Close() conn.Close()
cipher, err = ssclient.NewCipher("chacha20", "new-password") cipher, err = ssclient.NewCipher("chacha20", "new-password")
@ -85,7 +84,7 @@ func TestShadowsocksTCP(t *testing.T) {
response = make([]byte, 1024) response = make([]byte, 1024)
nBytes, err = conn.Read(response) nBytes, err = conn.Read(response)
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response[:nBytes])) assert.String("Processed: " + payload).Equals(string(response[:nBytes]))
conn.Close() conn.Close()
CloseAllServers() CloseAllServers()

View File

@ -6,14 +6,13 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" 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/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
"github.com/v2ray/v2ray-core/testing/servers/udp" "github.com/v2ray/v2ray-core/testing/servers/udp"
) )
func TestTCPConnection(t *testing.T) { func TestTCPConnection(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
targetPort := v2nettesting.PickPort() targetPort := v2nettesting.PickPort()
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
@ -79,7 +78,7 @@ func TestTCPConnection(t *testing.T) {
nResponse += nBytes nResponse += nBytes
conn.CloseWrite() conn.CloseWrite()
assert.StringLiteral(string(actualResponse[:nResponse])).Equals("Processed: Request to target server.Processed: Request to target server again.") assert.String(string(actualResponse[:nResponse])).Equals("Processed: Request to target server.Processed: Request to target server again.")
conn.Close() conn.Close()
} }
@ -88,7 +87,7 @@ func TestTCPConnection(t *testing.T) {
} }
func TestTCPBind(t *testing.T) { func TestTCPBind(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
targetPort := v2nettesting.PickPort() targetPort := v2nettesting.PickPort()
tcpServer := &tcp.Server{ tcpServer := &tcp.Server{
@ -139,7 +138,7 @@ func TestTCPBind(t *testing.T) {
} }
func TestUDPAssociate(t *testing.T) { func TestUDPAssociate(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
targetPort := v2nettesting.PickPort() targetPort := v2nettesting.PickPort()
udpServer := &udp.Server{ udpServer := &udp.Server{

View File

@ -6,7 +6,6 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
@ -32,7 +31,7 @@ func allFilesExists(files ...string) bool {
} }
func TestBuildMacOS(t *testing.T) { func TestBuildMacOS(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
binPath = filepath.Join(os.Getenv("GOPATH"), "testing") binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
cleanBinPath() cleanBinPath()

View File

@ -3,12 +3,11 @@ package main
import ( import (
"testing" "testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestParseOS(t *testing.T) { func TestParseOS(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
assert.Pointer(parseOS("windows")).Equals(Windows) assert.Pointer(parseOS("windows")).Equals(Windows)
assert.Pointer(parseOS("macos")).Equals(MacOS) assert.Pointer(parseOS("macos")).Equals(MacOS)
@ -17,7 +16,7 @@ func TestParseOS(t *testing.T) {
} }
func TestParseArch(t *testing.T) { func TestParseArch(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
assert.Pointer(parseArch("x86")).Equals(X86) assert.Pointer(parseArch("x86")).Equals(X86)
assert.Pointer(parseArch("x64")).Equals(Amd64) assert.Pointer(parseArch("x64")).Equals(Amd64)

View File

@ -10,12 +10,11 @@ import (
"testing" "testing"
"time" "time"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestBuildAndRun(t *testing.T) { func TestBuildAndRun(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
gopath := os.Getenv("GOPATH") gopath := os.Getenv("GOPATH")
goOS := parseOS(runtime.GOOS) goOS := parseOS(runtime.GOOS)
@ -42,7 +41,7 @@ func TestBuildAndRun(t *testing.T) {
errStr := string(errBuffer.Bytes()) errStr := string(errBuffer.Bytes())
assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue() assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue()
assert.StringLiteral(errStr).Equals("") assert.String(errStr).Equals("")
os.Remove(target) os.Remove(target)
} }

View File

@ -3,12 +3,11 @@ package git
import ( import (
"testing" "testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
) )
func TestRevParse(t *testing.T) { func TestRevParse(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
rev, err := RevParse("HEAD") rev, err := RevParse("HEAD")
assert.Error(err).IsNil() assert.Error(err).IsNil()
@ -16,7 +15,7 @@ func TestRevParse(t *testing.T) {
} }
func TestRepoVersion(t *testing.T) { func TestRepoVersion(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
version, err := RepoVersionHead() version, err := RepoVersionHead()
assert.Error(err).IsNil() assert.Error(err).IsNil()

View File

@ -5,14 +5,13 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing" 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/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp" "github.com/v2ray/v2ray-core/testing/servers/tcp"
. "github.com/v2ray/v2ray-core/transport/dialer" . "github.com/v2ray/v2ray-core/transport/dialer"
) )
func TestDialDomain(t *testing.T) { func TestDialDomain(t *testing.T) {
v2testing.Current(t) assert := assert.On(t)
server := &tcp.Server{ server := &tcp.Server{
Port: v2nettesting.PickPort(), Port: v2nettesting.PickPort(),
@ -23,6 +22,6 @@ func TestDialDomain(t *testing.T) {
conn, err := Dial(v2net.TCPDestination(v2net.DomainAddress("local.v2ray.com"), dest.Port())) conn, err := Dial(v2net.TCPDestination(v2net.DomainAddress("local.v2ray.com"), dest.Port()))
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.StringLiteral(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port().String()) assert.String(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port().String())
conn.Close() conn.Close()
} }