Browse Source

remove dep on assert lib

Darien Raymond 6 years ago
parent
commit
bdd71a44b4
35 changed files with 365 additions and 324 deletions
  1. 9 8
      app/stats/command/command_test.go
  2. 3 3
      common/buf/reader_test.go
  3. 4 4
      common/buf/writer_test.go
  4. 7 7
      common/crypto/auth_test.go
  5. 1 1
      common/crypto/chunk_test.go
  6. 13 12
      common/mux/mux_test.go
  7. 3 2
      common/platform/platform_test.go
  8. 2 2
      common/protocol/http/headers_test.go
  9. 4 3
      common/retry/retry_test.go
  10. 19 14
      common/signal/timer_test.go
  11. 10 7
      common/task/task_test.go
  12. 10 7
      common/type_test.go
  13. 1 1
      common/uuid/uuid_test.go
  14. 16 8
      proxy/mtproto/auth_test.go
  15. 32 29
      proxy/shadowsocks/protocol_test.go
  16. 2 2
      proxy/vmess/encoding/encoding_test.go
  17. 18 10
      proxy/vmess/validator_test.go
  18. 22 21
      testing/scenarios/command_test.go
  19. 7 6
      testing/scenarios/dns_test.go
  20. 5 5
      testing/scenarios/dokodemo_test.go
  21. 38 38
      testing/scenarios/feature_test.go
  22. 23 23
      testing/scenarios/http_test.go
  23. 8 8
      testing/scenarios/shadowsocks_test.go
  24. 26 26
      testing/scenarios/socks_test.go
  25. 13 13
      testing/scenarios/vmess_test.go
  26. 12 12
      transport/internet/headers/http/http_test.go
  27. 2 1
      transport/internet/headers/tls/dtls_test.go
  28. 5 5
      transport/internet/headers/utp/utp_test.go
  29. 5 5
      transport/internet/http/http_test.go
  30. 3 2
      transport/internet/kcp/kcp_test.go
  31. 15 15
      transport/internet/quic/quic_test.go
  32. 2 2
      transport/internet/tcp/sockopt_linux_test.go
  33. 5 4
      transport/internet/tls/config_test.go
  34. 2 1
      transport/internet/udp/dispatcher_test.go
  35. 18 17
      transport/internet/websocket/ws_test.go

+ 9 - 8
app/stats/command/command_test.go

@@ -6,6 +6,7 @@ import (
 
 
 	"v2ray.com/core/app/stats"
 	"v2ray.com/core/app/stats"
 	. "v2ray.com/core/app/stats/command"
 	. "v2ray.com/core/app/stats/command"
+	"v2ray.com/core/common"
 	. "v2ray.com/ext/assert"
 	. "v2ray.com/ext/assert"
 )
 )
 
 
@@ -13,10 +14,10 @@ func TestGetStats(t *testing.T) {
 	assert := With(t)
 	assert := With(t)
 
 
 	m, err := stats.NewManager(context.Background(), &stats.Config{})
 	m, err := stats.NewManager(context.Background(), &stats.Config{})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	sc, err := m.RegisterCounter("test_counter")
 	sc, err := m.RegisterCounter("test_counter")
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	sc.Set(1)
 	sc.Set(1)
 
 
@@ -50,7 +51,7 @@ func TestGetStats(t *testing.T) {
 		if tc.err {
 		if tc.err {
 			assert(err, IsNotNil)
 			assert(err, IsNotNil)
 		} else {
 		} else {
-			assert(err, IsNil)
+			common.Must(err)
 			assert(resp.Stat.Name, Equals, tc.name)
 			assert(resp.Stat.Name, Equals, tc.name)
 			assert(resp.Stat.Value, Equals, tc.value)
 			assert(resp.Stat.Value, Equals, tc.value)
 		}
 		}
@@ -61,25 +62,25 @@ func TestQueryStats(t *testing.T) {
 	assert := With(t)
 	assert := With(t)
 
 
 	m, err := stats.NewManager(context.Background(), &stats.Config{})
 	m, err := stats.NewManager(context.Background(), &stats.Config{})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	sc1, err := m.RegisterCounter("test_counter")
 	sc1, err := m.RegisterCounter("test_counter")
-	assert(err, IsNil)
+	common.Must(err)
 	sc1.Set(1)
 	sc1.Set(1)
 
 
 	sc2, err := m.RegisterCounter("test_counter_2")
 	sc2, err := m.RegisterCounter("test_counter_2")
-	assert(err, IsNil)
+	common.Must(err)
 	sc2.Set(2)
 	sc2.Set(2)
 
 
 	sc3, err := m.RegisterCounter("test_counter_3")
 	sc3, err := m.RegisterCounter("test_counter_3")
-	assert(err, IsNil)
+	common.Must(err)
 	sc3.Set(3)
 	sc3.Set(3)
 
 
 	s := NewStatsServer(m)
 	s := NewStatsServer(m)
 	resp, err := s.QueryStats(context.Background(), &QueryStatsRequest{
 	resp, err := s.QueryStats(context.Background(), &QueryStatsRequest{
 		Pattern: "counter_",
 		Pattern: "counter_",
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	assert(len(resp.Stat), Equals, 2)
 	assert(len(resp.Stat), Equals, 2)
 
 
 	v2 := false
 	v2 := false

+ 3 - 3
common/buf/reader_test.go

@@ -28,11 +28,11 @@ func TestBytesReaderWriteTo(t *testing.T) {
 	writer.SetBuffered(false)
 	writer.SetBuffered(false)
 
 
 	nBytes, err := io.Copy(writer, reader)
 	nBytes, err := io.Copy(writer, reader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(nBytes, Equals, int64(6))
 	assert(nBytes, Equals, int64(6))
 
 
 	mb, err := pReader2.ReadMultiBuffer()
 	mb, err := pReader2.ReadMultiBuffer()
-	assert(err, IsNil)
+	common.Must(err)
 	assert(len(mb), Equals, 2)
 	assert(len(mb), Equals, 2)
 	assert(mb[0].String(), Equals, "abc")
 	assert(mb[0].String(), Equals, "abc")
 	assert(mb[1].String(), Equals, "efg")
 	assert(mb[1].String(), Equals, "efg")
@@ -52,7 +52,7 @@ func TestBytesReaderMultiBuffer(t *testing.T) {
 
 
 	mbReader := NewReader(reader)
 	mbReader := NewReader(reader)
 	mb, err := mbReader.ReadMultiBuffer()
 	mb, err := mbReader.ReadMultiBuffer()
-	assert(err, IsNil)
+	common.Must(err)
 	assert(len(mb), Equals, 2)
 	assert(len(mb), Equals, 2)
 	assert(mb[0].String(), Equals, "abc")
 	assert(mb[0].String(), Equals, "abc")
 	assert(mb[1].String(), Equals, "efg")
 	assert(mb[1].String(), Equals, "efg")

+ 4 - 4
common/buf/writer_test.go

@@ -26,7 +26,7 @@ func TestWriter(t *testing.T) {
 	writer := NewBufferedWriter(NewWriter(writeBuffer))
 	writer := NewBufferedWriter(NewWriter(writeBuffer))
 	writer.SetBuffered(false)
 	writer.SetBuffered(false)
 	err := writer.WriteMultiBuffer(MultiBuffer{lb})
 	err := writer.WriteMultiBuffer(MultiBuffer{lb})
-	assert(err, IsNil)
+	common.Must(err)
 	assert(writer.Flush(), IsNil)
 	assert(writer.Flush(), IsNil)
 	assert(expectedBytes, Equals, writeBuffer.Bytes())
 	assert(expectedBytes, Equals, writeBuffer.Bytes())
 }
 }
@@ -46,7 +46,7 @@ func TestBytesWriterReadFrom(t *testing.T) {
 	}
 	}
 
 
 	mb, err := pReader.ReadMultiBuffer()
 	mb, err := pReader.ReadMultiBuffer()
-	assert(err, IsNil)
+	common.Must(err)
 	assert(mb.Len(), Equals, int32(size))
 	assert(mb.Len(), Equals, int32(size))
 }
 }
 
 
@@ -58,7 +58,7 @@ func TestDiscardBytes(t *testing.T) {
 
 
 	nBytes, err := io.Copy(DiscardBytes, b)
 	nBytes, err := io.Copy(DiscardBytes, b)
 	assert(nBytes, Equals, int64(Size))
 	assert(nBytes, Equals, int64(Size))
-	assert(err, IsNil)
+	common.Must(err)
 }
 }
 
 
 func TestDiscardBytesMultiBuffer(t *testing.T) {
 func TestDiscardBytesMultiBuffer(t *testing.T) {
@@ -71,7 +71,7 @@ func TestDiscardBytesMultiBuffer(t *testing.T) {
 	r := NewReader(buffer)
 	r := NewReader(buffer)
 	nBytes, err := io.Copy(DiscardBytes, &BufferedReader{Reader: r})
 	nBytes, err := io.Copy(DiscardBytes, &BufferedReader{Reader: r})
 	assert(nBytes, Equals, int64(size))
 	assert(nBytes, Equals, int64(size))
-	assert(err, IsNil)
+	common.Must(err)
 }
 }
 
 
 func TestWriterInterface(t *testing.T) {
 func TestWriterInterface(t *testing.T) {

+ 7 - 7
common/crypto/auth_test.go

@@ -21,10 +21,10 @@ func TestAuthenticationReaderWriter(t *testing.T) {
 	key := make([]byte, 16)
 	key := make([]byte, 16)
 	rand.Read(key)
 	rand.Read(key)
 	block, err := aes.NewCipher(key)
 	block, err := aes.NewCipher(key)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	aead, err := cipher.NewGCM(block)
 	aead, err := cipher.NewGCM(block)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	const payloadSize = 1024 * 80
 	const payloadSize = 1024 * 80
 	rawPayload := make([]byte, payloadSize)
 	rawPayload := make([]byte, payloadSize)
@@ -57,7 +57,7 @@ func TestAuthenticationReaderWriter(t *testing.T) {
 
 
 	for mb.Len() < payloadSize {
 	for mb.Len() < payloadSize {
 		mb2, err := reader.ReadMultiBuffer()
 		mb2, err := reader.ReadMultiBuffer()
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		mb, _ = buf.MergeMulti(mb, mb2)
 		mb, _ = buf.MergeMulti(mb, mb2)
 	}
 	}
@@ -78,10 +78,10 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) {
 	key := make([]byte, 16)
 	key := make([]byte, 16)
 	common.Must2(rand.Read(key))
 	common.Must2(rand.Read(key))
 	block, err := aes.NewCipher(key)
 	block, err := aes.NewCipher(key)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	aead, err := cipher.NewGCM(block)
 	aead, err := cipher.NewGCM(block)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	cache := buf.New()
 	cache := buf.New()
 	iv := make([]byte, 12)
 	iv := make([]byte, 12)
@@ -105,7 +105,7 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) {
 	assert(writer.WriteMultiBuffer(payload), IsNil)
 	assert(writer.WriteMultiBuffer(payload), IsNil)
 	assert(cache.Len(), GreaterThan, int32(0))
 	assert(cache.Len(), GreaterThan, int32(0))
 	assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil)
 	assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	reader := NewAuthenticationReader(&AEADAuthenticator{
 	reader := NewAuthenticationReader(&AEADAuthenticator{
 		AEAD:                    aead,
 		AEAD:                    aead,
@@ -114,7 +114,7 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) {
 	}, PlainChunkSizeParser{}, cache, protocol.TransferTypePacket, nil)
 	}, PlainChunkSizeParser{}, cache, protocol.TransferTypePacket, nil)
 
 
 	mb, err := reader.ReadMultiBuffer()
 	mb, err := reader.ReadMultiBuffer()
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	mb, b1 := buf.SplitFirst(mb)
 	mb, b1 := buf.SplitFirst(mb)
 	assert(b1.String(), Equals, "abcd")
 	assert(b1.String(), Equals, "abcd")

+ 1 - 1
common/crypto/chunk_test.go

@@ -40,7 +40,7 @@ func TestChunkStreamIO(t *testing.T) {
 	assert(mb[0].Bytes(), Equals, []byte("abcd"))
 	assert(mb[0].Bytes(), Equals, []byte("abcd"))
 
 
 	mb, err = reader.ReadMultiBuffer()
 	mb, err = reader.ReadMultiBuffer()
-	assert(err, IsNil)
+	common.Must(err)
 	assert(mb.Len(), Equals, int32(3))
 	assert(mb.Len(), Equals, int32(3))
 	assert(mb[0].Bytes(), Equals, []byte("efg"))
 	assert(mb[0].Bytes(), Equals, []byte("efg"))
 
 

+ 13 - 12
common/mux/mux_test.go

@@ -4,6 +4,7 @@ import (
 	"io"
 	"io"
 	"testing"
 	"testing"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	. "v2ray.com/core/common/mux"
 	. "v2ray.com/core/common/mux"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
@@ -63,72 +64,72 @@ func TestReaderWriter(t *testing.T) {
 
 
 	var meta FrameMetadata
 	var meta FrameMetadata
 	err := meta.Unmarshal(bytesReader)
 	err := meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(meta.SessionID, Equals, uint16(1))
 	assert(meta.SessionID, Equals, uint16(1))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
 	assert(meta.Target, Equals, dest)
 	assert(meta.Target, Equals, dest)
 	assert(byte(meta.Option), Equals, byte(OptionData))
 	assert(byte(meta.Option), Equals, byte(OptionData))
 
 
 	data, err := readAll(NewStreamReader(bytesReader))
 	data, err := readAll(NewStreamReader(bytesReader))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(len(data), Equals, 1)
 	assert(len(data), Equals, 1)
 	assert(data[0].String(), Equals, "abcd")
 	assert(data[0].String(), Equals, "abcd")
 
 
 	err = meta.Unmarshal(bytesReader)
 	err = meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
 	assert(meta.SessionID, Equals, uint16(2))
 	assert(meta.SessionID, Equals, uint16(2))
 	assert(byte(meta.Option), Equals, byte(0))
 	assert(byte(meta.Option), Equals, byte(0))
 	assert(meta.Target, Equals, dest2)
 	assert(meta.Target, Equals, dest2)
 
 
 	err = meta.Unmarshal(bytesReader)
 	err = meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
 	assert(meta.SessionID, Equals, uint16(1))
 	assert(meta.SessionID, Equals, uint16(1))
 	assert(byte(meta.Option), Equals, byte(1))
 	assert(byte(meta.Option), Equals, byte(1))
 
 
 	data, err = readAll(NewStreamReader(bytesReader))
 	data, err = readAll(NewStreamReader(bytesReader))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(len(data), Equals, 1)
 	assert(len(data), Equals, 1)
 	assert(data[0].String(), Equals, "efgh")
 	assert(data[0].String(), Equals, "efgh")
 
 
 	err = meta.Unmarshal(bytesReader)
 	err = meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
 	assert(meta.SessionID, Equals, uint16(3))
 	assert(meta.SessionID, Equals, uint16(3))
 	assert(byte(meta.Option), Equals, byte(1))
 	assert(byte(meta.Option), Equals, byte(1))
 	assert(meta.Target, Equals, dest3)
 	assert(meta.Target, Equals, dest3)
 
 
 	data, err = readAll(NewStreamReader(bytesReader))
 	data, err = readAll(NewStreamReader(bytesReader))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(len(data), Equals, 1)
 	assert(len(data), Equals, 1)
 	assert(data[0].String(), Equals, "x")
 	assert(data[0].String(), Equals, "x")
 
 
 	err = meta.Unmarshal(bytesReader)
 	err = meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
 	assert(meta.SessionID, Equals, uint16(1))
 	assert(meta.SessionID, Equals, uint16(1))
 	assert(byte(meta.Option), Equals, byte(0))
 	assert(byte(meta.Option), Equals, byte(0))
 
 
 	err = meta.Unmarshal(bytesReader)
 	err = meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
 	assert(meta.SessionID, Equals, uint16(3))
 	assert(meta.SessionID, Equals, uint16(3))
 	assert(byte(meta.Option), Equals, byte(0))
 	assert(byte(meta.Option), Equals, byte(0))
 
 
 	err = meta.Unmarshal(bytesReader)
 	err = meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
 	assert(meta.SessionID, Equals, uint16(2))
 	assert(meta.SessionID, Equals, uint16(2))
 	assert(byte(meta.Option), Equals, byte(1))
 	assert(byte(meta.Option), Equals, byte(1))
 
 
 	data, err = readAll(NewStreamReader(bytesReader))
 	data, err = readAll(NewStreamReader(bytesReader))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(len(data), Equals, 1)
 	assert(len(data), Equals, 1)
 	assert(data[0].String(), Equals, "y")
 	assert(data[0].String(), Equals, "y")
 
 
 	err = meta.Unmarshal(bytesReader)
 	err = meta.Unmarshal(bytesReader)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
 	assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
 	assert(meta.SessionID, Equals, uint16(2))
 	assert(meta.SessionID, Equals, uint16(2))
 	assert(byte(meta.Option), Equals, byte(0))
 	assert(byte(meta.Option), Equals, byte(0))

+ 3 - 2
common/platform/platform_test.go

@@ -6,6 +6,7 @@ import (
 	"runtime"
 	"runtime"
 	"testing"
 	"testing"
 
 
+	"v2ray.com/core/common"
 	. "v2ray.com/core/common/platform"
 	. "v2ray.com/core/common/platform"
 	. "v2ray.com/ext/assert"
 	. "v2ray.com/ext/assert"
 )
 )
@@ -47,7 +48,7 @@ func TestGetAssetLocation(t *testing.T) {
 	assert := With(t)
 	assert := With(t)
 
 
 	exec, err := os.Executable()
 	exec, err := os.Executable()
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	loc := GetAssetLocation("t")
 	loc := GetAssetLocation("t")
 	assert(filepath.Dir(loc), Equals, filepath.Dir(exec))
 	assert(filepath.Dir(loc), Equals, filepath.Dir(exec))
@@ -64,7 +65,7 @@ func TestGetPluginLocation(t *testing.T) {
 	assert := With(t)
 	assert := With(t)
 
 
 	exec, err := os.Executable()
 	exec, err := os.Executable()
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	loc := GetPluginDirectory()
 	loc := GetPluginDirectory()
 	assert(loc, Equals, filepath.Join(filepath.Dir(exec), "plugins"))
 	assert(loc, Equals, filepath.Join(filepath.Dir(exec), "plugins"))

+ 2 - 2
common/protocol/http/headers_test.go

@@ -6,8 +6,8 @@ import (
 	"strings"
 	"strings"
 	"testing"
 	"testing"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
-
 	. "v2ray.com/core/common/protocol/http"
 	. "v2ray.com/core/common/protocol/http"
 	. "v2ray.com/ext/assert"
 	. "v2ray.com/ext/assert"
 )
 )
@@ -41,7 +41,7 @@ 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(err, IsNil)
+	common.Must(err)
 	assert(req.Header.Get("Foo"), Equals, "foo")
 	assert(req.Header.Get("Foo"), Equals, "foo")
 	assert(req.Header.Get("Bar"), Equals, "bar")
 	assert(req.Header.Get("Bar"), Equals, "bar")
 	assert(req.Header.Get("Connection"), Equals, "keep-alive,Foo, Bar")
 	assert(req.Header.Get("Connection"), Equals, "keep-alive,Foo, Bar")

+ 4 - 3
common/retry/retry_test.go

@@ -4,6 +4,7 @@ import (
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/errors"
 	"v2ray.com/core/common/errors"
 	. "v2ray.com/core/common/retry"
 	. "v2ray.com/core/common/retry"
 	. "v2ray.com/ext/assert"
 	. "v2ray.com/ext/assert"
@@ -22,7 +23,7 @@ func TestNoRetry(t *testing.T) {
 	})
 	})
 	endTime := time.Now().Unix()
 	endTime := time.Now().Unix()
 
 
-	assert(err, IsNil)
+	common.Must(err)
 	assert(endTime-startTime, AtLeast, int64(0))
 	assert(endTime-startTime, AtLeast, int64(0))
 }
 }
 
 
@@ -40,7 +41,7 @@ func TestRetryOnce(t *testing.T) {
 	})
 	})
 	duration := time.Since(startTime)
 	duration := time.Since(startTime)
 
 
-	assert(err, IsNil)
+	common.Must(err)
 	assert(int64(duration/time.Millisecond), AtLeast, int64(900))
 	assert(int64(duration/time.Millisecond), AtLeast, int64(900))
 }
 }
 
 
@@ -58,7 +59,7 @@ func TestRetryMultiple(t *testing.T) {
 	})
 	})
 	duration := time.Since(startTime)
 	duration := time.Since(startTime)
 
 
-	assert(err, IsNil)
+	common.Must(err)
 	assert(int64(duration/time.Millisecond), AtLeast, int64(4900))
 	assert(int64(duration/time.Millisecond), AtLeast, int64(4900))
 }
 }
 
 

+ 19 - 14
common/signal/timer_test.go

@@ -7,49 +7,54 @@ import (
 	"time"
 	"time"
 
 
 	. "v2ray.com/core/common/signal"
 	. "v2ray.com/core/common/signal"
-	. "v2ray.com/ext/assert"
 )
 )
 
 
 func TestActivityTimer(t *testing.T) {
 func TestActivityTimer(t *testing.T) {
-	assert := With(t)
-
 	ctx, cancel := context.WithCancel(context.Background())
 	ctx, cancel := context.WithCancel(context.Background())
 	timer := CancelAfterInactivity(ctx, cancel, time.Second*4)
 	timer := CancelAfterInactivity(ctx, cancel, time.Second*4)
 	time.Sleep(time.Second * 6)
 	time.Sleep(time.Second * 6)
-	assert(ctx.Err(), IsNotNil)
+	if ctx.Err() == nil {
+		t.Error("expected some error, but got nil")
+	}
 	runtime.KeepAlive(timer)
 	runtime.KeepAlive(timer)
 }
 }
 
 
 func TestActivityTimerUpdate(t *testing.T) {
 func TestActivityTimerUpdate(t *testing.T) {
-	assert := With(t)
-
 	ctx, cancel := context.WithCancel(context.Background())
 	ctx, cancel := context.WithCancel(context.Background())
 	timer := CancelAfterInactivity(ctx, cancel, time.Second*10)
 	timer := CancelAfterInactivity(ctx, cancel, time.Second*10)
 	time.Sleep(time.Second * 3)
 	time.Sleep(time.Second * 3)
-	assert(ctx.Err(), IsNil)
+	if ctx.Err() != nil {
+		t.Error("expected nil, but got ", ctx.Err().Error())
+	}
 	timer.SetTimeout(time.Second * 1)
 	timer.SetTimeout(time.Second * 1)
 	time.Sleep(time.Second * 2)
 	time.Sleep(time.Second * 2)
-	assert(ctx.Err(), IsNotNil)
+	if ctx.Err() == nil {
+		t.Error("expcted some error, but got nil")
+	}
 	runtime.KeepAlive(timer)
 	runtime.KeepAlive(timer)
 }
 }
 
 
 func TestActivityTimerNonBlocking(t *testing.T) {
 func TestActivityTimerNonBlocking(t *testing.T) {
-	assert := With(t)
-
 	ctx, cancel := context.WithCancel(context.Background())
 	ctx, cancel := context.WithCancel(context.Background())
 	timer := CancelAfterInactivity(ctx, cancel, 0)
 	timer := CancelAfterInactivity(ctx, cancel, 0)
 	time.Sleep(time.Second * 1)
 	time.Sleep(time.Second * 1)
-	assert(ctx, HasDone)
+	select {
+	case <-ctx.Done():
+	default:
+		t.Error("context not done")
+	}
 	timer.SetTimeout(0)
 	timer.SetTimeout(0)
 	timer.SetTimeout(1)
 	timer.SetTimeout(1)
 	timer.SetTimeout(2)
 	timer.SetTimeout(2)
 }
 }
 
 
 func TestActivityTimerZeroTimeout(t *testing.T) {
 func TestActivityTimerZeroTimeout(t *testing.T) {
-	assert := With(t)
-
 	ctx, cancel := context.WithCancel(context.Background())
 	ctx, cancel := context.WithCancel(context.Background())
 	timer := CancelAfterInactivity(ctx, cancel, 0)
 	timer := CancelAfterInactivity(ctx, cancel, 0)
-	assert(ctx, HasDone)
+	select {
+	case <-ctx.Done():
+	default:
+		t.Error("context not done")
+	}
 	runtime.KeepAlive(timer)
 	runtime.KeepAlive(timer)
 }
 }

+ 10 - 7
common/task/task_test.go

@@ -3,17 +3,17 @@ package task_test
 import (
 import (
 	"context"
 	"context"
 	"errors"
 	"errors"
+	"strings"
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
+	"github.com/google/go-cmp/cmp"
+
 	"v2ray.com/core/common"
 	"v2ray.com/core/common"
 	. "v2ray.com/core/common/task"
 	. "v2ray.com/core/common/task"
-	. "v2ray.com/ext/assert"
 )
 )
 
 
 func TestExecuteParallel(t *testing.T) {
 func TestExecuteParallel(t *testing.T) {
-	assert := With(t)
-
 	err := Run(context.Background(),
 	err := Run(context.Background(),
 		func() error {
 		func() error {
 			time.Sleep(time.Millisecond * 200)
 			time.Sleep(time.Millisecond * 200)
@@ -23,12 +23,12 @@ func TestExecuteParallel(t *testing.T) {
 			return errors.New("test2")
 			return errors.New("test2")
 		})
 		})
 
 
-	assert(err.Error(), Equals, "test")
+	if r := cmp.Diff(err.Error(), "test"); r != "" {
+		t.Error(r)
+	}
 }
 }
 
 
 func TestExecuteParallelContextCancel(t *testing.T) {
 func TestExecuteParallelContextCancel(t *testing.T) {
-	assert := With(t)
-
 	ctx, cancel := context.WithCancel(context.Background())
 	ctx, cancel := context.WithCancel(context.Background())
 	err := Run(ctx, func() error {
 	err := Run(ctx, func() error {
 		time.Sleep(time.Millisecond * 2000)
 		time.Sleep(time.Millisecond * 2000)
@@ -41,7 +41,10 @@ func TestExecuteParallelContextCancel(t *testing.T) {
 		return nil
 		return nil
 	})
 	})
 
 
-	assert(err.Error(), HasSubstring, "canceled")
+	errStr := err.Error()
+	if !strings.Contains(errStr, "canceled") {
+		t.Error("expected error string to contain 'canceled', but actually not: ", errStr)
+	}
 }
 }
 
 
 func BenchmarkExecuteOne(b *testing.B) {
 func BenchmarkExecuteOne(b *testing.B) {

+ 10 - 7
common/type_test.go

@@ -5,7 +5,6 @@ import (
 	"testing"
 	"testing"
 
 
 	. "v2ray.com/core/common"
 	. "v2ray.com/core/common"
-	. "v2ray.com/ext/assert"
 )
 )
 
 
 type TConfig struct {
 type TConfig struct {
@@ -17,8 +16,6 @@ type YConfig struct {
 }
 }
 
 
 func TestObjectCreation(t *testing.T) {
 func TestObjectCreation(t *testing.T) {
-	assert := With(t)
-
 	var f = func(ctx context.Context, t interface{}) (interface{}, error) {
 	var f = func(ctx context.Context, t interface{}) (interface{}, error) {
 		return func() int {
 		return func() int {
 			return t.(*TConfig).value
 			return t.(*TConfig).value
@@ -27,12 +24,18 @@ func TestObjectCreation(t *testing.T) {
 
 
 	Must(RegisterConfig((*TConfig)(nil), f))
 	Must(RegisterConfig((*TConfig)(nil), f))
 	err := RegisterConfig((*TConfig)(nil), f)
 	err := RegisterConfig((*TConfig)(nil), f)
-	assert(err, IsNotNil)
+	if err == nil {
+		t.Error("expect non-nil error, but got nil")
+	}
 
 
 	g, err := CreateObject(context.Background(), &TConfig{value: 2})
 	g, err := CreateObject(context.Background(), &TConfig{value: 2})
-	assert(err, IsNil)
-	assert(g.(func() int)(), Equals, 2)
+	Must(err)
+	if v := g.(func() int)(); v != 2 {
+		t.Error("expect return value 2, but got ", v)
+	}
 
 
 	_, err = CreateObject(context.Background(), &YConfig{value: "T"})
 	_, err = CreateObject(context.Background(), &YConfig{value: "T"})
-	assert(err, IsNotNil)
+	if err == nil {
+		t.Error("expect non-nil error, but got nil")
+	}
 }
 }

+ 1 - 1
common/uuid/uuid_test.go

@@ -53,7 +53,7 @@ func TestNewUUID(t *testing.T) {
 	uuid := New()
 	uuid := New()
 	uuid2, err := ParseString(uuid.String())
 	uuid2, err := ParseString(uuid.String())
 
 
-	assert(err, IsNil)
+	common.Must(err)
 	assert(uuid.String(), Equals, uuid2.String())
 	assert(uuid.String(), Equals, uuid2.String())
 	assert(uuid.Bytes(), Equals, uuid2.Bytes())
 	assert(uuid.Bytes(), Equals, uuid2.Bytes())
 }
 }

+ 16 - 8
proxy/mtproto/auth_test.go

@@ -9,7 +9,6 @@ import (
 
 
 	"v2ray.com/core/common"
 	"v2ray.com/core/common"
 	. "v2ray.com/core/proxy/mtproto"
 	. "v2ray.com/core/proxy/mtproto"
-	. "v2ray.com/ext/assert"
 )
 )
 
 
 func TestInverse(t *testing.T) {
 func TestInverse(t *testing.T) {
@@ -31,15 +30,24 @@ func TestInverse(t *testing.T) {
 }
 }
 
 
 func TestAuthenticationReadWrite(t *testing.T) {
 func TestAuthenticationReadWrite(t *testing.T) {
-	assert := With(t)
-
 	a := NewAuthentication(DefaultSessionContext())
 	a := NewAuthentication(DefaultSessionContext())
 	b := bytes.NewReader(a.Header[:])
 	b := bytes.NewReader(a.Header[:])
 	a2, err := ReadAuthentication(b)
 	a2, err := ReadAuthentication(b)
-	assert(err, IsNil)
+	common.Must(err)
+
+	if r := cmp.Diff(a.EncodingKey[:], a2.DecodingKey[:]); r != "" {
+		t.Error("decoding key: ", r)
+	}
+
+	if r := cmp.Diff(a.EncodingNonce[:], a2.DecodingNonce[:]); r != "" {
+		t.Error("decoding nonce: ", r)
+	}
+
+	if r := cmp.Diff(a.DecodingKey[:], a2.EncodingKey[:]); r != "" {
+		t.Error("encoding key: ", r)
+	}
 
 
-	assert(a.EncodingKey[:], Equals, a2.DecodingKey[:])
-	assert(a.EncodingNonce[:], Equals, a2.DecodingNonce[:])
-	assert(a.DecodingKey[:], Equals, a2.EncodingKey[:])
-	assert(a.DecodingNonce[:], Equals, a2.EncodingNonce[:])
+	if r := cmp.Diff(a.DecodingNonce[:], a2.EncodingNonce[:]); r != "" {
+		t.Error("encoding nonce: ", r)
+	}
 }
 }

+ 32 - 29
proxy/shadowsocks/protocol_test.go

@@ -3,12 +3,13 @@ package shadowsocks_test
 import (
 import (
 	"testing"
 	"testing"
 
 
+	"github.com/google/go-cmp/cmp"
+
 	"v2ray.com/core/common"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/protocol"
 	. "v2ray.com/core/proxy/shadowsocks"
 	. "v2ray.com/core/proxy/shadowsocks"
-	. "v2ray.com/ext/assert"
 )
 )
 
 
 func toAccount(a *Account) protocol.Account {
 func toAccount(a *Account) protocol.Account {
@@ -18,8 +19,6 @@ func toAccount(a *Account) protocol.Account {
 }
 }
 
 
 func TestUDPEncoding(t *testing.T) {
 func TestUDPEncoding(t *testing.T) {
-	assert := With(t)
-
 	request := &protocol.RequestHeader{
 	request := &protocol.RequestHeader{
 		Version: Version,
 		Version: Version,
 		Command: protocol.RequestCommandUDP,
 		Command: protocol.RequestCommandUDP,
@@ -38,19 +37,21 @@ func TestUDPEncoding(t *testing.T) {
 	data := buf.New()
 	data := buf.New()
 	common.Must2(data.WriteString("test string"))
 	common.Must2(data.WriteString("test string"))
 	encodedData, err := EncodeUDPPacket(request, data.Bytes())
 	encodedData, err := EncodeUDPPacket(request, data.Bytes())
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	decodedRequest, decodedData, err := DecodeUDPPacket(request.User, encodedData)
 	decodedRequest, decodedData, err := DecodeUDPPacket(request.User, encodedData)
-	assert(err, IsNil)
-	assert(decodedData.Bytes(), Equals, data.Bytes())
-	assert(decodedRequest.Address, Equals, request.Address)
-	assert(decodedRequest.Port, Equals, request.Port)
-	assert(decodedRequest.Command, Equals, request.Command)
+	common.Must(err)
+
+	if r := cmp.Diff(decodedData.Bytes(), data.Bytes()); r != "" {
+		t.Error("data: ", r)
+	}
+
+	if r := cmp.Diff(decodedRequest, request); r != "" {
+		t.Error("request: ", r)
+	}
 }
 }
 
 
 func TestTCPRequest(t *testing.T) {
 func TestTCPRequest(t *testing.T) {
-	assert := With(t)
-
 	cases := []struct {
 	cases := []struct {
 		request *protocol.RequestHeader
 		request *protocol.RequestHeader
 		payload []byte
 		payload []byte
@@ -116,19 +117,21 @@ func TestTCPRequest(t *testing.T) {
 		defer cache.Release()
 		defer cache.Release()
 
 
 		writer, err := WriteTCPRequest(request, cache)
 		writer, err := WriteTCPRequest(request, cache)
-		assert(err, IsNil)
+		common.Must(err)
 
 
-		assert(writer.WriteMultiBuffer(buf.MultiBuffer{data}), IsNil)
+		common.Must(writer.WriteMultiBuffer(buf.MultiBuffer{data}))
 
 
 		decodedRequest, reader, err := ReadTCPSession(request.User, cache)
 		decodedRequest, reader, err := ReadTCPSession(request.User, cache)
-		assert(err, IsNil)
-		assert(decodedRequest.Address, Equals, request.Address)
-		assert(decodedRequest.Port, Equals, request.Port)
-		assert(decodedRequest.Command, Equals, request.Command)
+		common.Must(err)
+		if r := cmp.Diff(decodedRequest, request); r != "" {
+			t.Error("request: ", r)
+		}
 
 
 		decodedData, err := reader.ReadMultiBuffer()
 		decodedData, err := reader.ReadMultiBuffer()
-		assert(err, IsNil)
-		assert(decodedData[0].String(), Equals, string(payload))
+		common.Must(err)
+		if r := cmp.Diff(decodedData[0].Bytes(), payload); r != "" {
+			t.Error("data: ", r)
+		}
 	}
 	}
 
 
 	for _, test := range cases {
 	for _, test := range cases {
@@ -138,8 +141,6 @@ func TestTCPRequest(t *testing.T) {
 }
 }
 
 
 func TestUDPReaderWriter(t *testing.T) {
 func TestUDPReaderWriter(t *testing.T) {
-	assert := With(t)
-
 	user := &protocol.MemoryUser{
 	user := &protocol.MemoryUser{
 		Account: toAccount(&Account{
 		Account: toAccount(&Account{
 			Password:   "test-password",
 			Password:   "test-password",
@@ -168,22 +169,24 @@ func TestUDPReaderWriter(t *testing.T) {
 	{
 	{
 		b := buf.New()
 		b := buf.New()
 		common.Must2(b.WriteString("test payload"))
 		common.Must2(b.WriteString("test payload"))
-		err := writer.WriteMultiBuffer(buf.MultiBuffer{b})
-		assert(err, IsNil)
+		common.Must(writer.WriteMultiBuffer(buf.MultiBuffer{b}))
 
 
 		payload, err := reader.ReadMultiBuffer()
 		payload, err := reader.ReadMultiBuffer()
-		assert(err, IsNil)
-		assert(payload[0].String(), Equals, "test payload")
+		common.Must(err)
+		if payload[0].String() != "test payload" {
+			t.Error("unexpected output: ", payload[0].String())
+		}
 	}
 	}
 
 
 	{
 	{
 		b := buf.New()
 		b := buf.New()
 		common.Must2(b.WriteString("test payload 2"))
 		common.Must2(b.WriteString("test payload 2"))
-		err := writer.WriteMultiBuffer(buf.MultiBuffer{b})
-		assert(err, IsNil)
+		common.Must(writer.WriteMultiBuffer(buf.MultiBuffer{b}))
 
 
 		payload, err := reader.ReadMultiBuffer()
 		payload, err := reader.ReadMultiBuffer()
-		assert(err, IsNil)
-		assert(payload[0].String(), Equals, "test payload 2")
+		common.Must(err)
+		if payload[0].String() != "test payload 2" {
+			t.Error("unexpected output: ", payload[0].String())
+		}
 	}
 	}
 }
 }

+ 2 - 2
proxy/vmess/encoding/encoding_test.go

@@ -58,7 +58,7 @@ func TestRequestSerialization(t *testing.T) {
 
 
 	server := NewServerSession(userValidator, sessionHistory)
 	server := NewServerSession(userValidator, sessionHistory)
 	actualRequest, err := server.DecodeRequestHeader(buffer)
 	actualRequest, err := server.DecodeRequestHeader(buffer)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	assert(expectedRequest.Version, Equals, actualRequest.Version)
 	assert(expectedRequest.Version, Equals, actualRequest.Version)
 	assert(byte(expectedRequest.Command), Equals, byte(actualRequest.Command))
 	assert(byte(expectedRequest.Command), Equals, byte(actualRequest.Command))
@@ -151,7 +151,7 @@ func TestMuxRequest(t *testing.T) {
 
 
 	server := NewServerSession(userValidator, sessionHistory)
 	server := NewServerSession(userValidator, sessionHistory)
 	actualRequest, err := server.DecodeRequestHeader(buffer)
 	actualRequest, err := server.DecodeRequestHeader(buffer)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	assert(expectedRequest.Version, Equals, actualRequest.Version)
 	assert(expectedRequest.Version, Equals, actualRequest.Version)
 	assert(byte(expectedRequest.Command), Equals, byte(actualRequest.Command))
 	assert(byte(expectedRequest.Command), Equals, byte(actualRequest.Command))

+ 18 - 10
proxy/vmess/validator_test.go

@@ -9,12 +9,9 @@ import (
 	"v2ray.com/core/common/serial"
 	"v2ray.com/core/common/serial"
 	"v2ray.com/core/common/uuid"
 	"v2ray.com/core/common/uuid"
 	. "v2ray.com/core/proxy/vmess"
 	. "v2ray.com/core/proxy/vmess"
-	. "v2ray.com/ext/assert"
 )
 )
 
 
 func TestUserValidator(t *testing.T) {
 func TestUserValidator(t *testing.T) {
-	assert := With(t)
-
 	hasher := protocol.DefaultIDHash
 	hasher := protocol.DefaultIDHash
 	v := NewTimedUserValidator(hasher)
 	v := NewTimedUserValidator(hasher)
 	defer common.Close(v)
 	defer common.Close(v)
@@ -43,9 +40,15 @@ func TestUserValidator(t *testing.T) {
 			userHash := idHash.Sum(nil)
 			userHash := idHash.Sum(nil)
 
 
 			euser, ets, found := v.Get(userHash)
 			euser, ets, found := v.Get(userHash)
-			assert(found, IsTrue)
-			assert(euser.Email, Equals, user.Email)
-			assert(int64(ets), Equals, int64(ts))
+			if !found {
+				t.Fatal("user not found")
+			}
+			if euser.Email != user.Email {
+				t.Error("unexpected user email: ", euser.Email, " want ", user.Email)
+			}
+			if ets != ts {
+				t.Error("unexpected timestamp: ", ets, " want ", ts)
+			}
 		}
 		}
 
 
 		testSmallLag(0)
 		testSmallLag(0)
@@ -65,8 +68,9 @@ func TestUserValidator(t *testing.T) {
 			userHash := idHash.Sum(nil)
 			userHash := idHash.Sum(nil)
 
 
 			euser, _, found := v.Get(userHash)
 			euser, _, found := v.Get(userHash)
-			assert(found, IsFalse)
-			assert(euser, IsNil)
+			if found || euser != nil {
+				t.Error("unexpected user")
+			}
 		}
 		}
 
 
 		testBigLag(121)
 		testBigLag(121)
@@ -77,6 +81,10 @@ func TestUserValidator(t *testing.T) {
 		testBigLag(-500)
 		testBigLag(-500)
 	}
 	}
 
 
-	assert(v.Remove(user.Email), IsTrue)
-	assert(v.Remove(user.Email), IsFalse)
+	if v := v.Remove(user.Email); !v {
+		t.Error("unable to remove user")
+	}
+	if v := v.Remove(user.Email); v {
+		t.Error("remove user twice")
+	}
 }
 }

+ 22 - 21
testing/scenarios/command_test.go

@@ -18,6 +18,7 @@ import (
 	"v2ray.com/core/app/router"
 	"v2ray.com/core/app/router"
 	"v2ray.com/core/app/stats"
 	"v2ray.com/core/app/stats"
 	statscmd "v2ray.com/core/app/stats/command"
 	statscmd "v2ray.com/core/app/stats/command"
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/serial"
 	"v2ray.com/core/common/serial"
@@ -38,7 +39,7 @@ func TestCommanderRemoveHandler(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	clientPort := tcp.PickPort()
 	clientPort := tcp.PickPort()
@@ -97,7 +98,7 @@ func TestCommanderRemoveHandler(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(clientConfig)
 	servers, err := InitializeServerConfigs(clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	defer CloseAllServers(servers)
 	defer CloseAllServers(servers)
 
 
@@ -113,26 +114,26 @@ func TestCommanderRemoveHandler(t *testing.T) {
 
 
 		payload := "commander request."
 		payload := "commander request."
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		if r := cmp.Diff(response[:nBytes], xor([]byte(payload))); r != "" {
 		if r := cmp.Diff(response[:nBytes], xor([]byte(payload))); r != "" {
 			t.Fatal(r)
 			t.Fatal(r)
 		}
 		}
 	}
 	}
 
 
 	cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
 	cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
-	assert(err, IsNil)
+	common.Must(err)
 	defer cmdConn.Close()
 	defer cmdConn.Close()
 
 
 	hsClient := command.NewHandlerServiceClient(cmdConn)
 	hsClient := command.NewHandlerServiceClient(cmdConn)
 	resp, err := hsClient.RemoveInbound(context.Background(), &command.RemoveInboundRequest{
 	resp, err := hsClient.RemoveInbound(context.Background(), &command.RemoveInboundRequest{
 		Tag: "d",
 		Tag: "d",
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	assert(resp, IsNotNil)
 	assert(resp, IsNotNil)
 
 
 	{
 	{
@@ -151,7 +152,7 @@ func TestCommanderAddRemoveUser(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	u1 := protocol.NewID(uuid.New())
 	u1 := protocol.NewID(uuid.New())
@@ -282,18 +283,18 @@ func TestCommanderAddRemoveUser(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 		conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 			IP:   []byte{127, 0, 0, 1},
 			IP:   []byte{127, 0, 0, 1},
 			Port: int(clientPort),
 			Port: int(clientPort),
 		})
 		})
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "commander request."
 		payload := "commander request."
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
@@ -304,7 +305,7 @@ func TestCommanderAddRemoveUser(t *testing.T) {
 	}
 	}
 
 
 	cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
 	cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
-	assert(err, IsNil)
+	common.Must(err)
 	defer cmdConn.Close()
 	defer cmdConn.Close()
 
 
 	hsClient := command.NewHandlerServiceClient(cmdConn)
 	hsClient := command.NewHandlerServiceClient(cmdConn)
@@ -321,7 +322,7 @@ func TestCommanderAddRemoveUser(t *testing.T) {
 				},
 				},
 			}),
 			}),
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	assert(resp, IsNotNil)
 	assert(resp, IsNotNil)
 
 
 	{
 	{
@@ -329,16 +330,16 @@ func TestCommanderAddRemoveUser(t *testing.T) {
 			IP:   []byte{127, 0, 0, 1},
 			IP:   []byte{127, 0, 0, 1},
 			Port: int(clientPort),
 			Port: int(clientPort),
 		})
 		})
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "commander request."
 		payload := "commander request."
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}
@@ -348,7 +349,7 @@ func TestCommanderAddRemoveUser(t *testing.T) {
 		Operation: serial.ToTypedMessage(&command.RemoveUserOperation{Email: "test@v2ray.com"}),
 		Operation: serial.ToTypedMessage(&command.RemoveUserOperation{Email: "test@v2ray.com"}),
 	})
 	})
 	assert(resp, IsNotNil)
 	assert(resp, IsNotNil)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	CloseAllServers(servers)
 	CloseAllServers(servers)
 }
 }
@@ -360,7 +361,7 @@ func TestCommanderStats(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	userID := protocol.NewID(uuid.New())
 	userID := protocol.NewID(uuid.New())
@@ -503,7 +504,7 @@ func TestCommanderStats(t *testing.T) {
 	}
 	}
 
 
 	cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
 	cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
-	assert(err, IsNil)
+	common.Must(err)
 	defer cmdConn.Close()
 	defer cmdConn.Close()
 
 
 	const name = "user>>>test>>>traffic>>>uplink"
 	const name = "user>>>test>>>traffic>>>uplink"
@@ -513,14 +514,14 @@ func TestCommanderStats(t *testing.T) {
 		Name:   name,
 		Name:   name,
 		Reset_: true,
 		Reset_: true,
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	assert(sresp.Stat.Name, Equals, name)
 	assert(sresp.Stat.Name, Equals, name)
 	assert(sresp.Stat.Value, Equals, int64(10240*1024))
 	assert(sresp.Stat.Value, Equals, int64(10240*1024))
 
 
 	sresp, err = sClient.GetStats(context.Background(), &statscmd.GetStatsRequest{
 	sresp, err = sClient.GetStats(context.Background(), &statscmd.GetStatsRequest{
 		Name: name,
 		Name: name,
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	assert(sresp.Stat.Name, Equals, name)
 	assert(sresp.Stat.Name, Equals, name)
 	assert(sresp.Stat.Value, Equals, int64(0))
 	assert(sresp.Stat.Value, Equals, int64(0))
 
 
@@ -528,6 +529,6 @@ func TestCommanderStats(t *testing.T) {
 		Name:   "inbound>>>vmess>>>traffic>>>uplink",
 		Name:   "inbound>>>vmess>>>traffic>>>uplink",
 		Reset_: true,
 		Reset_: true,
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	assert(sresp.Stat.Value, GreaterThan, int64(10240*1024))
 	assert(sresp.Stat.Value, GreaterThan, int64(10240*1024))
 }
 }

+ 7 - 6
testing/scenarios/dns_test.go

@@ -9,6 +9,7 @@ import (
 	"v2ray.com/core/app/dns"
 	"v2ray.com/core/app/dns"
 	"v2ray.com/core/app/proxyman"
 	"v2ray.com/core/app/proxyman"
 	"v2ray.com/core/app/router"
 	"v2ray.com/core/app/router"
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/serial"
 	"v2ray.com/core/common/serial"
 	"v2ray.com/core/proxy/blackhole"
 	"v2ray.com/core/proxy/blackhole"
@@ -25,7 +26,7 @@ func TestResolveIP(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -83,22 +84,22 @@ func TestResolveIP(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
 		noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
-		assert(err, IsNil)
+		common.Must(err)
 		conn, err := noAuthDialer.Dial("tcp", fmt.Sprintf("google.com:%d", dest.Port))
 		conn, err := noAuthDialer.Dial("tcp", fmt.Sprintf("google.com:%d", dest.Port))
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "test payload"
 		payload := "test payload"
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}

+ 5 - 5
testing/scenarios/dokodemo_test.go

@@ -127,7 +127,7 @@ func TestDokodemoUDP(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := udpServer.Start()
 	dest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	userID := protocol.NewID(uuid.New())
 	userID := protocol.NewID(uuid.New())
@@ -197,23 +197,23 @@ func TestDokodemoUDP(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	for port := clientPort; port <= clientPort+clientPortRange; port++ {
 	for port := clientPort; port <= clientPort+clientPortRange; port++ {
 		conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 		conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 			IP:   []byte{127, 0, 0, 1},
 			IP:   []byte{127, 0, 0, 1},
 			Port: int(port),
 			Port: int(port),
 		})
 		})
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "dokodemo request."
 		payload := "dokodemo request."
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}

+ 38 - 38
testing/scenarios/feature_test.go

@@ -44,7 +44,7 @@ func TestPassiveConnection(t *testing.T) {
 		SendFirst:    []byte("send first"),
 		SendFirst:    []byte("send first"),
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -72,18 +72,18 @@ func TestPassiveConnection(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 	conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 		IP:   []byte{127, 0, 0, 1},
 		IP:   []byte{127, 0, 0, 1},
 		Port: int(serverPort),
 		Port: int(serverPort),
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err := conn.Read(response)
 		nBytes, err := conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(string(response[:nBytes]), Equals, "send first")
 		assert(string(response[:nBytes]), Equals, "send first")
 	}
 	}
 
 
@@ -91,14 +91,14 @@ func TestPassiveConnection(t *testing.T) {
 	{
 	{
 
 
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 	}
 	}
 
 
 	{
 	{
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err := conn.Read(response)
 		nBytes, err := conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 	}
 	}
 
 
@@ -246,7 +246,7 @@ func TestProxyOverKCP(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	serverUserID := protocol.NewID(uuid.New())
 	serverUserID := protocol.NewID(uuid.New())
@@ -376,22 +376,22 @@ func TestProxyOverKCP(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, proxyConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, proxyConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 	conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 		IP:   []byte{127, 0, 0, 1},
 		IP:   []byte{127, 0, 0, 1},
 		Port: int(clientPort),
 		Port: int(clientPort),
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	payload := "dokodemo request."
 	payload := "dokodemo request."
 	nBytes, err := conn.Write([]byte(payload))
 	nBytes, err := conn.Write([]byte(payload))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(nBytes, Equals, len(payload))
 	assert(nBytes, Equals, len(payload))
 
 
 	response := make([]byte, 1024)
 	response := make([]byte, 1024)
 	nBytes, err = conn.Read(response)
 	nBytes, err = conn.Read(response)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(conn.Close(), IsNil)
 	assert(conn.Close(), IsNil)
 
 
@@ -405,14 +405,14 @@ func TestBlackhole(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	tcpServer2 := tcp.Server{
 	tcpServer2 := tcp.Server{
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest2, err := tcpServer2.Start()
 	dest2, err := tcpServer2.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer2.Close()
 	defer tcpServer2.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -471,19 +471,19 @@ func TestBlackhole(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 	conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
 		IP:   []byte{127, 0, 0, 1},
 		IP:   []byte{127, 0, 0, 1},
 		Port: int(serverPort2),
 		Port: int(serverPort2),
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	payload := "dokodemo request."
 	payload := "dokodemo request."
 	{
 	{
 
 
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 	}
 	}
 
 
@@ -505,7 +505,7 @@ func TestForward(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -541,22 +541,22 @@ func TestForward(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
 		noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
-		assert(err, IsNil)
+		common.Must(err)
 		conn, err := noAuthDialer.Dial("tcp", "google.com:80")
 		conn, err := noAuthDialer.Dial("tcp", "google.com:80")
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "test payload"
 		payload := "test payload"
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}
@@ -571,7 +571,7 @@ func TestUDPConnection(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := udpServer.Start()
 	dest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	clientPort := tcp.PickPort()
 	clientPort := tcp.PickPort()
@@ -599,24 +599,24 @@ func TestUDPConnection(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(clientConfig)
 	servers, err := InitializeServerConfigs(clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 		conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 			IP:   []byte{127, 0, 0, 1},
 			IP:   []byte{127, 0, 0, 1},
 			Port: int(clientPort),
 			Port: int(clientPort),
 		})
 		})
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "dokodemo request."
 		payload := "dokodemo request."
 		for i := 0; i < 5; i++ {
 		for i := 0; i < 5; i++ {
 			nBytes, err := conn.Write([]byte(payload))
 			nBytes, err := conn.Write([]byte(payload))
-			assert(err, IsNil)
+			common.Must(err)
 			assert(nBytes, Equals, len(payload))
 			assert(nBytes, Equals, len(payload))
 
 
 			response := make([]byte, 1024)
 			response := make([]byte, 1024)
 			nBytes, err = conn.Read(response)
 			nBytes, err = conn.Read(response)
-			assert(err, IsNil)
+			common.Must(err)
 			assert(response[:nBytes], Equals, xor([]byte(payload)))
 			assert(response[:nBytes], Equals, xor([]byte(payload)))
 		}
 		}
 
 
@@ -630,16 +630,16 @@ func TestUDPConnection(t *testing.T) {
 			IP:   []byte{127, 0, 0, 1},
 			IP:   []byte{127, 0, 0, 1},
 			Port: int(clientPort),
 			Port: int(clientPort),
 		})
 		})
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "dokodemo request."
 		payload := "dokodemo request."
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}
@@ -721,7 +721,7 @@ func TestDomainSniffing(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		transport := &http.Transport{
 		transport := &http.Transport{
@@ -735,7 +735,7 @@ func TestDomainSniffing(t *testing.T) {
 		}
 		}
 
 
 		resp, err := client.Get("https://www.github.com/")
 		resp, err := client.Get("https://www.github.com/")
-		assert(err, IsNil)
+		common.Must(err)
 		assert(resp.StatusCode, Equals, 200)
 		assert(resp.StatusCode, Equals, 200)
 
 
 		assert(resp.Write(ioutil.Discard), IsNil)
 		assert(resp.Write(ioutil.Discard), IsNil)
@@ -751,7 +751,7 @@ func TestDialV2Ray(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	userID := protocol.NewID(uuid.New())
 	userID := protocol.NewID(uuid.New())
@@ -821,22 +821,22 @@ func TestDialV2Ray(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	client, err := core.New(clientConfig)
 	client, err := core.New(clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	conn, err := core.Dial(context.Background(), client, dest)
 	conn, err := core.Dial(context.Background(), client, dest)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	payload := "commander request."
 	payload := "commander request."
 	nBytes, err := conn.Write([]byte(payload))
 	nBytes, err := conn.Write([]byte(payload))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(nBytes, Equals, len(payload))
 	assert(nBytes, Equals, len(payload))
 
 
 	response := make([]byte, 1024)
 	response := make([]byte, 1024)
 	nBytes, err = conn.Read(response)
 	nBytes, err = conn.Read(response)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(conn.Close(), IsNil)
 	assert(conn.Close(), IsNil)
 
 

+ 23 - 23
testing/scenarios/http_test.go

@@ -32,7 +32,7 @@ func TestHttpConformance(t *testing.T) {
 		PathHandler: make(map[string]http.HandlerFunc),
 		PathHandler: make(map[string]http.HandlerFunc),
 	}
 	}
 	_, err := httpServer.Start()
 	_, err := httpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer httpServer.Close()
 	defer httpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -54,7 +54,7 @@ func TestHttpConformance(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		transport := &http.Transport{
 		transport := &http.Transport{
@@ -68,11 +68,11 @@ func TestHttpConformance(t *testing.T) {
 		}
 		}
 
 
 		resp, err := client.Get("http://127.0.0.1:" + httpServerPort.String())
 		resp, err := client.Get("http://127.0.0.1:" + httpServerPort.String())
-		assert(err, IsNil)
+		common.Must(err)
 		assert(resp.StatusCode, Equals, 200)
 		assert(resp.StatusCode, Equals, 200)
 
 
 		content, err := ioutil.ReadAll(resp.Body)
 		content, err := ioutil.ReadAll(resp.Body)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(string(content), Equals, "Home")
 		assert(string(content), Equals, "Home")
 
 
 	}
 	}
@@ -89,7 +89,7 @@ func TestHttpError(t *testing.T) {
 		},
 		},
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	time.AfterFunc(time.Second*2, func() {
 	time.AfterFunc(time.Second*2, func() {
@@ -115,7 +115,7 @@ func TestHttpError(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		transport := &http.Transport{
 		transport := &http.Transport{
@@ -129,7 +129,7 @@ func TestHttpError(t *testing.T) {
 		}
 		}
 
 
 		resp, err := client.Get("http://127.0.0.1:" + dest.Port.String())
 		resp, err := client.Get("http://127.0.0.1:" + dest.Port.String())
-		assert(err, IsNil)
+		common.Must(err)
 		assert(resp.StatusCode, Equals, 503)
 		assert(resp.StatusCode, Equals, 503)
 	}
 	}
 
 
@@ -143,7 +143,7 @@ func TestHttpConnectMethod(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -165,7 +165,7 @@ func TestHttpConnectMethod(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		transport := &http.Transport{
 		transport := &http.Transport{
@@ -186,12 +186,12 @@ func TestHttpConnectMethod(t *testing.T) {
 		common.Must(err)
 		common.Must(err)
 
 
 		resp, err := client.Do(req)
 		resp, err := client.Do(req)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(resp.StatusCode, Equals, 200)
 		assert(resp.StatusCode, Equals, 200)
 
 
 		content := make([]byte, len(payload))
 		content := make([]byte, len(payload))
 		common.Must2(io.ReadFull(resp.Body, content))
 		common.Must2(io.ReadFull(resp.Body, content))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(content, Equals, xor(payload))
 		assert(content, Equals, xor(payload))
 
 
 	}
 	}
@@ -222,7 +222,7 @@ func TestHttpPost(t *testing.T) {
 	}
 	}
 
 
 	_, err := httpServer.Start()
 	_, err := httpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer httpServer.Close()
 	defer httpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -244,7 +244,7 @@ func TestHttpPost(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		transport := &http.Transport{
 		transport := &http.Transport{
@@ -261,11 +261,11 @@ func TestHttpPost(t *testing.T) {
 		common.Must2(rand.Read(payload))
 		common.Must2(rand.Read(payload))
 
 
 		resp, err := client.Post("http://127.0.0.1:"+httpServerPort.String()+"/testpost", "application/x-www-form-urlencoded", bytes.NewReader(payload))
 		resp, err := client.Post("http://127.0.0.1:"+httpServerPort.String()+"/testpost", "application/x-www-form-urlencoded", bytes.NewReader(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(resp.StatusCode, Equals, 200)
 		assert(resp.StatusCode, Equals, 200)
 
 
 		content, err := ioutil.ReadAll(resp.Body)
 		content, err := ioutil.ReadAll(resp.Body)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(content, Equals, xor(payload))
 		assert(content, Equals, xor(payload))
 
 
 	}
 	}
@@ -288,7 +288,7 @@ func TestHttpBasicAuth(t *testing.T) {
 		PathHandler: make(map[string]http.HandlerFunc),
 		PathHandler: make(map[string]http.HandlerFunc),
 	}
 	}
 	_, err := httpServer.Start()
 	_, err := httpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer httpServer.Close()
 	defer httpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -314,7 +314,7 @@ func TestHttpBasicAuth(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		transport := &http.Transport{
 		transport := &http.Transport{
@@ -329,31 +329,31 @@ func TestHttpBasicAuth(t *testing.T) {
 
 
 		{
 		{
 			resp, err := client.Get("http://127.0.0.1:" + httpServerPort.String())
 			resp, err := client.Get("http://127.0.0.1:" + httpServerPort.String())
-			assert(err, IsNil)
+			common.Must(err)
 			assert(resp.StatusCode, Equals, 407)
 			assert(resp.StatusCode, Equals, 407)
 		}
 		}
 
 
 		{
 		{
 			req, err := http.NewRequest("GET", "http://127.0.0.1:"+httpServerPort.String(), nil)
 			req, err := http.NewRequest("GET", "http://127.0.0.1:"+httpServerPort.String(), nil)
-			assert(err, IsNil)
+			common.Must(err)
 
 
 			setProxyBasicAuth(req, "a", "c")
 			setProxyBasicAuth(req, "a", "c")
 			resp, err := client.Do(req)
 			resp, err := client.Do(req)
-			assert(err, IsNil)
+			common.Must(err)
 			assert(resp.StatusCode, Equals, 407)
 			assert(resp.StatusCode, Equals, 407)
 		}
 		}
 
 
 		{
 		{
 			req, err := http.NewRequest("GET", "http://127.0.0.1:"+httpServerPort.String(), nil)
 			req, err := http.NewRequest("GET", "http://127.0.0.1:"+httpServerPort.String(), nil)
-			assert(err, IsNil)
+			common.Must(err)
 
 
 			setProxyBasicAuth(req, "a", "b")
 			setProxyBasicAuth(req, "a", "b")
 			resp, err := client.Do(req)
 			resp, err := client.Do(req)
-			assert(err, IsNil)
+			common.Must(err)
 			assert(resp.StatusCode, Equals, 200)
 			assert(resp.StatusCode, Equals, 200)
 
 
 			content, err := ioutil.ReadAll(resp.Body)
 			content, err := ioutil.ReadAll(resp.Body)
-			assert(err, IsNil)
+			common.Must(err)
 			assert(string(content), Equals, "Home")
 			assert(string(content), Equals, "Home")
 		}
 		}
 	}
 	}

+ 8 - 8
testing/scenarios/shadowsocks_test.go

@@ -544,7 +544,7 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := udpServer.Start()
 	dest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	account := serial.ToTypedMessage(&shadowsocks.Account{
 	account := serial.ToTypedMessage(&shadowsocks.Account{
@@ -625,7 +625,7 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	var wg sync.WaitGroup
 	var wg sync.WaitGroup
 	wg.Add(10)
 	wg.Add(10)
@@ -635,13 +635,13 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
 				IP:   []byte{127, 0, 0, 1},
 				IP:   []byte{127, 0, 0, 1},
 				Port: int(clientPort),
 				Port: int(clientPort),
 			})
 			})
-			assert(err, IsNil)
+			common.Must(err)
 
 
 			payload := make([]byte, 1024)
 			payload := make([]byte, 1024)
 			rand.Read(payload)
 			rand.Read(payload)
 
 
 			nBytes, err := conn.Write([]byte(payload))
 			nBytes, err := conn.Write([]byte(payload))
-			assert(err, IsNil)
+			common.Must(err)
 			assert(nBytes, Equals, len(payload))
 			assert(nBytes, Equals, len(payload))
 
 
 			response := readFrom(conn, time.Second*5, 1024)
 			response := readFrom(conn, time.Second*5, 1024)
@@ -662,7 +662,7 @@ func TestShadowsocksAES128GCMUDPMux(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := udpServer.Start()
 	dest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	account := serial.ToTypedMessage(&shadowsocks.Account{
 	account := serial.ToTypedMessage(&shadowsocks.Account{
@@ -749,7 +749,7 @@ func TestShadowsocksAES128GCMUDPMux(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	var wg sync.WaitGroup
 	var wg sync.WaitGroup
 	wg.Add(10)
 	wg.Add(10)
@@ -759,13 +759,13 @@ func TestShadowsocksAES128GCMUDPMux(t *testing.T) {
 				IP:   []byte{127, 0, 0, 1},
 				IP:   []byte{127, 0, 0, 1},
 				Port: int(clientPort),
 				Port: int(clientPort),
 			})
 			})
-			assert(err, IsNil)
+			common.Must(err)
 
 
 			payload := make([]byte, 1024)
 			payload := make([]byte, 1024)
 			rand.Read(payload)
 			rand.Read(payload)
 
 
 			nBytes, err := conn.Write([]byte(payload))
 			nBytes, err := conn.Write([]byte(payload))
-			assert(err, IsNil)
+			common.Must(err)
 			assert(nBytes, Equals, len(payload))
 			assert(nBytes, Equals, len(payload))
 
 
 			response := readFrom(conn, time.Second*5, 1024)
 			response := readFrom(conn, time.Second*5, 1024)

+ 26 - 26
testing/scenarios/socks_test.go

@@ -111,7 +111,7 @@ func TestSocksBridageUDP(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := udpServer.Start()
 	dest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -179,22 +179,22 @@ func TestSocksBridageUDP(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 	conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 		IP:   []byte{127, 0, 0, 1},
 		IP:   []byte{127, 0, 0, 1},
 		Port: int(clientPort),
 		Port: int(clientPort),
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	payload := "dokodemo request."
 	payload := "dokodemo request."
 	nBytes, err := conn.Write([]byte(payload))
 	nBytes, err := conn.Write([]byte(payload))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(nBytes, Equals, len(payload))
 	assert(nBytes, Equals, len(payload))
 
 
 	response := make([]byte, 1024)
 	response := make([]byte, 1024)
 	nBytes, err = conn.Read(response)
 	nBytes, err = conn.Read(response)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(conn.Close(), IsNil)
 	assert(conn.Close(), IsNil)
 
 
@@ -208,7 +208,7 @@ func TestSocksBridageUDPWithRouting(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := udpServer.Start()
 	dest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	serverPort := tcp.PickPort()
 	serverPort := tcp.PickPort()
@@ -282,22 +282,22 @@ func TestSocksBridageUDPWithRouting(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 	conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
 		IP:   []byte{127, 0, 0, 1},
 		IP:   []byte{127, 0, 0, 1},
 		Port: int(clientPort),
 		Port: int(clientPort),
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	payload := "dokodemo request."
 	payload := "dokodemo request."
 	nBytes, err := conn.Write([]byte(payload))
 	nBytes, err := conn.Write([]byte(payload))
-	assert(err, IsNil)
+	common.Must(err)
 	assert(nBytes, Equals, len(payload))
 	assert(nBytes, Equals, len(payload))
 
 
 	response := make([]byte, 1024)
 	response := make([]byte, 1024)
 	nBytes, err = conn.Read(response)
 	nBytes, err = conn.Read(response)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(response[:nBytes], Equals, xor([]byte(payload)))
 	assert(conn.Close(), IsNil)
 	assert(conn.Close(), IsNil)
 
 
@@ -311,7 +311,7 @@ func TestSocksConformance(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	authPort := tcp.PickPort()
 	authPort := tcp.PickPort()
@@ -355,40 +355,40 @@ func TestSocksConformance(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig)
 	servers, err := InitializeServerConfigs(serverConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	{
 	{
 		noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr(), nil, xproxy.Direct)
 		noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr(), nil, xproxy.Direct)
-		assert(err, IsNil)
+		common.Must(err)
 		conn, err := noAuthDialer.Dial("tcp", dest.NetAddr())
 		conn, err := noAuthDialer.Dial("tcp", dest.NetAddr())
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "test payload"
 		payload := "test payload"
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}
 
 
 	{
 	{
 		authDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, authPort).NetAddr(), &xproxy.Auth{User: "Test Account", Password: "Test Password"}, xproxy.Direct)
 		authDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, authPort).NetAddr(), &xproxy.Auth{User: "Test Account", Password: "Test Password"}, xproxy.Direct)
-		assert(err, IsNil)
+		common.Must(err)
 		conn, err := authDialer.Dial("tcp", dest.NetAddr())
 		conn, err := authDialer.Dial("tcp", dest.NetAddr())
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "test payload"
 		payload := "test payload"
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}
@@ -396,16 +396,16 @@ func TestSocksConformance(t *testing.T) {
 	{
 	{
 		dialer := socks4.DialSocksProxy(socks4.SOCKS4, net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr())
 		dialer := socks4.DialSocksProxy(socks4.SOCKS4, net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr())
 		conn, err := dialer("tcp", dest.NetAddr())
 		conn, err := dialer("tcp", dest.NetAddr())
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "test payload"
 		payload := "test payload"
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}
@@ -413,16 +413,16 @@ func TestSocksConformance(t *testing.T) {
 	{
 	{
 		dialer := socks4.DialSocksProxy(socks4.SOCKS4A, net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr())
 		dialer := socks4.DialSocksProxy(socks4.SOCKS4A, net.TCPDestination(net.LocalHostIP, noAuthPort).NetAddr())
 		conn, err := dialer("tcp", net.TCPDestination(net.LocalHostDomain, tcpServer.Port).NetAddr())
 		conn, err := dialer("tcp", net.TCPDestination(net.LocalHostDomain, tcpServer.Port).NetAddr())
-		assert(err, IsNil)
+		common.Must(err)
 
 
 		payload := "test payload"
 		payload := "test payload"
 		nBytes, err := conn.Write([]byte(payload))
 		nBytes, err := conn.Write([]byte(payload))
-		assert(err, IsNil)
+		common.Must(err)
 		assert(nBytes, Equals, len(payload))
 		assert(nBytes, Equals, len(payload))
 
 
 		response := make([]byte, 1024)
 		response := make([]byte, 1024)
 		nBytes, err = conn.Read(response)
 		nBytes, err = conn.Read(response)
-		assert(err, IsNil)
+		common.Must(err)
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(response[:nBytes], Equals, xor([]byte(payload)))
 		assert(conn.Close(), IsNil)
 		assert(conn.Close(), IsNil)
 	}
 	}

+ 13 - 13
testing/scenarios/vmess_test.go

@@ -370,7 +370,7 @@ func TestVMessGCMUDP(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := udpServer.Start()
 	dest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	userID := protocol.NewID(uuid.New())
 	userID := protocol.NewID(uuid.New())
@@ -456,7 +456,7 @@ func TestVMessGCMUDP(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	var wg sync.WaitGroup
 	var wg sync.WaitGroup
 	wg.Add(10)
 	wg.Add(10)
@@ -466,19 +466,19 @@ func TestVMessGCMUDP(t *testing.T) {
 				IP:   []byte{127, 0, 0, 1},
 				IP:   []byte{127, 0, 0, 1},
 				Port: int(clientPort),
 				Port: int(clientPort),
 			})
 			})
-			assert(err, IsNil)
+			common.Must(err)
 
 
 			payload := make([]byte, 1024)
 			payload := make([]byte, 1024)
 			rand.Read(payload)
 			rand.Read(payload)
 
 
 			nBytes, err := conn.Write([]byte(payload))
 			nBytes, err := conn.Write([]byte(payload))
-			assert(err, IsNil)
+			common.Must(err)
 			assert(nBytes, Equals, len(payload))
 			assert(nBytes, Equals, len(payload))
 
 
 			payload1 := make([]byte, 1024)
 			payload1 := make([]byte, 1024)
 			rand.Read(payload1)
 			rand.Read(payload1)
 			nBytes, err = conn.Write([]byte(payload1))
 			nBytes, err = conn.Write([]byte(payload1))
-			assert(err, IsNil)
+			common.Must(err)
 			assert(nBytes, Equals, len(payload1))
 			assert(nBytes, Equals, len(payload1))
 
 
 			response := readFrom(conn, time.Second*5, 1024)
 			response := readFrom(conn, time.Second*5, 1024)
@@ -1082,14 +1082,14 @@ func TestVMessGCMMuxUDP(t *testing.T) {
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	udpServer := udp.Server{
 	udpServer := udp.Server{
 		MsgProcessor: xor,
 		MsgProcessor: xor,
 	}
 	}
 	udpDest, err := udpServer.Start()
 	udpDest, err := udpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer udpServer.Close()
 	defer udpServer.Close()
 
 
 	userID := protocol.NewID(uuid.New())
 	userID := protocol.NewID(uuid.New())
@@ -1195,7 +1195,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
 	}
 	}
 
 
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	for range "abcd" {
 	for range "abcd" {
 		var wg sync.WaitGroup
 		var wg sync.WaitGroup
@@ -1207,7 +1207,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
 					IP:   []byte{127, 0, 0, 1},
 					IP:   []byte{127, 0, 0, 1},
 					Port: int(clientPort),
 					Port: int(clientPort),
 				})
 				})
-				assert(err, IsNil)
+				common.Must(err)
 
 
 				payload := make([]byte, 10240)
 				payload := make([]byte, 10240)
 				rand.Read(payload)
 				rand.Read(payload)
@@ -1215,7 +1215,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
 				xorpayload := xor(payload)
 				xorpayload := xor(payload)
 
 
 				nBytes, err := conn.Write(payload)
 				nBytes, err := conn.Write(payload)
-				assert(err, IsNil)
+				common.Must(err)
 				assert(nBytes, Equals, len(payload))
 				assert(nBytes, Equals, len(payload))
 
 
 				response := readFrom(conn, time.Second*20, 10240)
 				response := readFrom(conn, time.Second*20, 10240)
@@ -1230,7 +1230,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
 					IP:   []byte{127, 0, 0, 1},
 					IP:   []byte{127, 0, 0, 1},
 					Port: int(clientUDPPort),
 					Port: int(clientUDPPort),
 				})
 				})
-				assert(err, IsNil)
+				common.Must(err)
 
 
 				conn.SetDeadline(time.Now().Add(time.Second * 10))
 				conn.SetDeadline(time.Now().Add(time.Second * 10))
 
 
@@ -1241,7 +1241,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
 
 
 				for j := 0; j < 2; j++ {
 				for j := 0; j < 2; j++ {
 					nBytes, _, err := conn.WriteMsgUDP(payload, nil, nil)
 					nBytes, _, err := conn.WriteMsgUDP(payload, nil, nil)
-					assert(err, IsNil)
+					common.Must(err)
 					assert(nBytes, Equals, len(payload))
 					assert(nBytes, Equals, len(payload))
 				}
 				}
 
 
@@ -1249,7 +1249,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
 				oob := make([]byte, 16)
 				oob := make([]byte, 16)
 				for j := 0; j < 2; j++ {
 				for j := 0; j < 2; j++ {
 					nBytes, _, _, _, err := conn.ReadMsgUDP(response, oob)
 					nBytes, _, _, _, err := conn.ReadMsgUDP(response, oob)
-					assert(err, IsNil)
+					common.Must(err)
 					assert(nBytes, Equals, 1024)
 					assert(nBytes, Equals, 1024)
 					assert(response, Equals, xorpayload)
 					assert(response, Equals, xorpayload)
 				}
 				}

+ 12 - 12
transport/internet/headers/http/http_test.go

@@ -22,14 +22,14 @@ func TestReaderWriter(t *testing.T) {
 	common.Must2(b.WriteString("abcd" + ENDING))
 	common.Must2(b.WriteString("abcd" + ENDING))
 	writer := NewHeaderWriter(b)
 	writer := NewHeaderWriter(b)
 	err := writer.Write(cache)
 	err := writer.Write(cache)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(cache.Len(), Equals, int32(8))
 	assert(cache.Len(), Equals, int32(8))
 	_, err = cache.Write([]byte{'e', 'f', 'g'})
 	_, err = cache.Write([]byte{'e', 'f', 'g'})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	reader := &HeaderReader{}
 	reader := &HeaderReader{}
 	buffer, err := reader.Read(cache)
 	buffer, err := reader.Read(cache)
-	assert(err, IsNil)
+	common.Must(err)
 	assert(buffer.Bytes(), Equals, []byte{'e', 'f', 'g'})
 	assert(buffer.Bytes(), Equals, []byte{'e', 'f', 'g'})
 }
 }
 
 
@@ -47,11 +47,11 @@ func TestRequestHeader(t *testing.T) {
 			},
 			},
 		},
 		},
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	cache := buf.New()
 	cache := buf.New()
 	err = auth.GetClientWriter().Write(cache)
 	err = auth.GetClientWriter().Write(cache)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	assert(cache.String(), Equals, "GET / HTTP/1.1\r\nTest: Value\r\n\r\n")
 	assert(cache.String(), Equals, "GET / HTTP/1.1\r\nTest: Value\r\n\r\n")
 }
 }
@@ -98,26 +98,26 @@ func TestConnection(t *testing.T) {
 			},
 			},
 		},
 		},
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	listener, err := net.Listen("tcp", "127.0.0.1:0")
 	listener, err := net.Listen("tcp", "127.0.0.1:0")
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	go func() {
 	go func() {
 		conn, err := listener.Accept()
 		conn, err := listener.Accept()
-		assert(err, IsNil)
+		common.Must(err)
 		authConn := auth.Server(conn)
 		authConn := auth.Server(conn)
 		b := make([]byte, 256)
 		b := make([]byte, 256)
 		for {
 		for {
 			n, err := authConn.Read(b)
 			n, err := authConn.Read(b)
-			assert(err, IsNil)
+			common.Must(err)
 			_, err = authConn.Write(b[:n])
 			_, err = authConn.Write(b[:n])
-			assert(err, IsNil)
+			common.Must(err)
 		}
 		}
 	}()
 	}()
 
 
 	conn, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr))
 	conn, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr))
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	authConn := auth.Client(conn)
 	authConn := auth.Client(conn)
 	authConn.Write([]byte("Test payload"))
 	authConn.Write([]byte("Test payload"))
@@ -129,7 +129,7 @@ func TestConnection(t *testing.T) {
 	totalBytes := 0
 	totalBytes := 0
 	for {
 	for {
 		n, err := authConn.Read(actualResponse[totalBytes:])
 		n, err := authConn.Read(actualResponse[totalBytes:])
-		assert(err, IsNil)
+		common.Must(err)
 		totalBytes += n
 		totalBytes += n
 		if totalBytes >= len(expectedResponse) || time.Now().After(deadline) {
 		if totalBytes >= len(expectedResponse) || time.Now().After(deadline) {
 			break
 			break

+ 2 - 1
transport/internet/headers/tls/dtls_test.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"context"
 	"testing"
 	"testing"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	. "v2ray.com/core/transport/internet/headers/tls"
 	. "v2ray.com/core/transport/internet/headers/tls"
 	. "v2ray.com/ext/assert"
 	. "v2ray.com/ext/assert"
@@ -14,7 +15,7 @@ func TestDTLSWrite(t *testing.T) {
 
 
 	content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
 	content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
 	dtlsRaw, err := New(context.Background(), &PacketConfig{})
 	dtlsRaw, err := New(context.Background(), &PacketConfig{})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	dtls := dtlsRaw.(*DTLS)
 	dtls := dtlsRaw.(*DTLS)
 
 

+ 5 - 5
transport/internet/headers/utp/utp_test.go

@@ -4,17 +4,15 @@ import (
 	"context"
 	"context"
 	"testing"
 	"testing"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	. "v2ray.com/core/transport/internet/headers/utp"
 	. "v2ray.com/core/transport/internet/headers/utp"
-	. "v2ray.com/ext/assert"
 )
 )
 
 
 func TestUTPWrite(t *testing.T) {
 func TestUTPWrite(t *testing.T) {
-	assert := With(t)
-
 	content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
 	content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
 	utpRaw, err := New(context.Background(), &Config{})
 	utpRaw, err := New(context.Background(), &Config{})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	utp := utpRaw.(*UTP)
 	utp := utpRaw.(*UTP)
 
 
@@ -22,5 +20,7 @@ func TestUTPWrite(t *testing.T) {
 	utp.Serialize(payload.Extend(utp.Size()))
 	utp.Serialize(payload.Extend(utp.Size()))
 	payload.Write(content)
 	payload.Write(content)
 
 
-	assert(payload.Len(), Equals, int32(len(content))+utp.Size())
+	if payload.Len() != int32(len(content))+utp.Size() {
+		t.Error("unexpected payload length: ", payload.Len())
+	}
 }
 }

+ 5 - 5
transport/internet/http/http_test.go

@@ -41,12 +41,12 @@ func TestHTTPConnection(t *testing.T) {
 					return
 					return
 				}
 				}
 				nBytes, err := conn.Write(b.Bytes())
 				nBytes, err := conn.Write(b.Bytes())
-				assert(err, IsNil)
+				common.Must(err)
 				assert(int32(nBytes), Equals, b.Len())
 				assert(int32(nBytes), Equals, b.Len())
 			}
 			}
 		}()
 		}()
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	defer listener.Close()
 	defer listener.Close()
 
 
@@ -62,7 +62,7 @@ func TestHTTPConnection(t *testing.T) {
 			AllowInsecure: true,
 			AllowInsecure: true,
 		},
 		},
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	defer conn.Close()
 	defer conn.Close()
 
 
 	const N = 1024
 	const N = 1024
@@ -72,7 +72,7 @@ func TestHTTPConnection(t *testing.T) {
 
 
 	nBytes, err := conn.Write(b1)
 	nBytes, err := conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))
@@ -80,7 +80,7 @@ func TestHTTPConnection(t *testing.T) {
 
 
 	nBytes, err = conn.Write(b1)
 	nBytes, err = conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))

+ 3 - 2
transport/internet/kcp/kcp_test.go

@@ -8,6 +8,7 @@ import (
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/internet"
 	. "v2ray.com/core/transport/internet/kcp"
 	. "v2ray.com/core/transport/internet/kcp"
@@ -36,7 +37,7 @@ func TestDialAndListen(t *testing.T) {
 			c.Close()
 			c.Close()
 		}(conn)
 		}(conn)
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	port := net.Port(listerner.Addr().(*net.UDPAddr).Port)
 	port := net.Port(listerner.Addr().(*net.UDPAddr).Port)
 
 
 	wg := new(sync.WaitGroup)
 	wg := new(sync.WaitGroup)
@@ -45,7 +46,7 @@ func TestDialAndListen(t *testing.T) {
 			ProtocolName:     "mkcp",
 			ProtocolName:     "mkcp",
 			ProtocolSettings: &Config{},
 			ProtocolSettings: &Config{},
 		})
 		})
-		assert(err, IsNil)
+		common.Must(err)
 		wg.Add(1)
 		wg.Add(1)
 
 
 		go func() {
 		go func() {

+ 15 - 15
transport/internet/quic/quic_test.go

@@ -45,12 +45,12 @@ func TestQuicConnection(t *testing.T) {
 					return
 					return
 				}
 				}
 				nBytes, err := conn.Write(b.Bytes())
 				nBytes, err := conn.Write(b.Bytes())
-				assert(err, IsNil)
+				common.Must(err)
 				assert(int32(nBytes), Equals, b.Len())
 				assert(int32(nBytes), Equals, b.Len())
 			}
 			}
 		}()
 		}()
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	defer listener.Close()
 	defer listener.Close()
 
 
@@ -66,7 +66,7 @@ func TestQuicConnection(t *testing.T) {
 			AllowInsecure: true,
 			AllowInsecure: true,
 		},
 		},
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	defer conn.Close()
 	defer conn.Close()
 
 
 	const N = 1024
 	const N = 1024
@@ -76,7 +76,7 @@ func TestQuicConnection(t *testing.T) {
 
 
 	nBytes, err := conn.Write(b1)
 	nBytes, err := conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))
@@ -84,7 +84,7 @@ func TestQuicConnection(t *testing.T) {
 
 
 	nBytes, err = conn.Write(b1)
 	nBytes, err = conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))
@@ -112,12 +112,12 @@ func TestQuicConnectionWithoutTLS(t *testing.T) {
 					return
 					return
 				}
 				}
 				nBytes, err := conn.Write(b.Bytes())
 				nBytes, err := conn.Write(b.Bytes())
-				assert(err, IsNil)
+				common.Must(err)
 				assert(int32(nBytes), Equals, b.Len())
 				assert(int32(nBytes), Equals, b.Len())
 			}
 			}
 		}()
 		}()
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	defer listener.Close()
 	defer listener.Close()
 
 
@@ -128,7 +128,7 @@ func TestQuicConnectionWithoutTLS(t *testing.T) {
 		ProtocolName:     "quic",
 		ProtocolName:     "quic",
 		ProtocolSettings: &quic.Config{},
 		ProtocolSettings: &quic.Config{},
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	defer conn.Close()
 	defer conn.Close()
 
 
 	const N = 1024
 	const N = 1024
@@ -138,7 +138,7 @@ func TestQuicConnectionWithoutTLS(t *testing.T) {
 
 
 	nBytes, err := conn.Write(b1)
 	nBytes, err := conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))
@@ -146,7 +146,7 @@ func TestQuicConnectionWithoutTLS(t *testing.T) {
 
 
 	nBytes, err = conn.Write(b1)
 	nBytes, err = conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))
@@ -180,12 +180,12 @@ func TestQuicConnectionAuthHeader(t *testing.T) {
 					return
 					return
 				}
 				}
 				nBytes, err := conn.Write(b.Bytes())
 				nBytes, err := conn.Write(b.Bytes())
-				assert(err, IsNil)
+				common.Must(err)
 				assert(int32(nBytes), Equals, b.Len())
 				assert(int32(nBytes), Equals, b.Len())
 			}
 			}
 		}()
 		}()
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	defer listener.Close()
 	defer listener.Close()
 
 
@@ -202,7 +202,7 @@ func TestQuicConnectionAuthHeader(t *testing.T) {
 			},
 			},
 		},
 		},
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	defer conn.Close()
 	defer conn.Close()
 
 
 	const N = 1024
 	const N = 1024
@@ -212,7 +212,7 @@ func TestQuicConnectionAuthHeader(t *testing.T) {
 
 
 	nBytes, err := conn.Write(b1)
 	nBytes, err := conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))
@@ -220,7 +220,7 @@ func TestQuicConnectionAuthHeader(t *testing.T) {
 
 
 	nBytes, err = conn.Write(b1)
 	nBytes, err = conn.Write(b1)
 	assert(nBytes, Equals, N)
 	assert(nBytes, Equals, N)
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	b2.Clear()
 	b2.Clear()
 	common.Must2(b2.ReadFullFrom(conn, N))
 	common.Must2(b2.ReadFullFrom(conn, N))

+ 2 - 2
transport/internet/tcp/sockopt_linux_test.go

@@ -19,13 +19,13 @@ func TestGetOriginalDestination(t *testing.T) {
 
 
 	tcpServer := tcp.Server{}
 	tcpServer := tcp.Server{}
 	dest, err := tcpServer.Start()
 	dest, err := tcpServer.Start()
-	assert(err, IsNil)
+	common.Must(err)
 	defer tcpServer.Close()
 	defer tcpServer.Close()
 
 
 	config, err := internet.ToMemoryStreamConfig(nil)
 	config, err := internet.ToMemoryStreamConfig(nil)
 	common.Must(err)
 	common.Must(err)
 	conn, err := Dial(context.Background(), dest, config)
 	conn, err := Dial(context.Background(), dest, config)
-	assert(err, IsNil)
+	common.Must(err)
 	defer conn.Close()
 	defer conn.Close()
 
 
 	originalDest, err := GetOriginalDestination(conn)
 	originalDest, err := GetOriginalDestination(conn)

+ 5 - 4
transport/internet/tls/config_test.go

@@ -6,6 +6,7 @@ import (
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/protocol/tls/cert"
 	"v2ray.com/core/common/protocol/tls/cert"
 	. "v2ray.com/core/transport/internet/tls"
 	. "v2ray.com/core/transport/internet/tls"
 	. "v2ray.com/ext/assert"
 	. "v2ray.com/ext/assert"
@@ -27,10 +28,10 @@ func TestCertificateIssuing(t *testing.T) {
 	v2rayCert, err := tlsConfig.GetCertificate(&gotls.ClientHelloInfo{
 	v2rayCert, err := tlsConfig.GetCertificate(&gotls.ClientHelloInfo{
 		ServerName: "www.v2ray.com",
 		ServerName: "www.v2ray.com",
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0])
 	x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0])
-	assert(err, IsNil)
+	common.Must(err)
 	assert(x509Cert.NotAfter.After(time.Now()), IsTrue)
 	assert(x509Cert.NotAfter.After(time.Now()), IsTrue)
 }
 }
 
 
@@ -56,10 +57,10 @@ func TestExpiredCertificate(t *testing.T) {
 	v2rayCert, err := tlsConfig.GetCertificate(&gotls.ClientHelloInfo{
 	v2rayCert, err := tlsConfig.GetCertificate(&gotls.ClientHelloInfo{
 		ServerName: "www.v2ray.com",
 		ServerName: "www.v2ray.com",
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0])
 	x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0])
-	assert(err, IsNil)
+	common.Must(err)
 	assert(x509Cert.NotAfter.After(time.Now()), IsTrue)
 	assert(x509Cert.NotAfter.After(time.Now()), IsTrue)
 }
 }
 
 

+ 2 - 1
transport/internet/udp/dispatcher_test.go

@@ -6,6 +6,7 @@ import (
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/protocol/udp"
 	"v2ray.com/core/common/protocol/udp"
@@ -50,7 +51,7 @@ func TestSameDestinationDispatching(t *testing.T) {
 				break
 				break
 			}
 			}
 			err = downlinkWriter.WriteMultiBuffer(data)
 			err = downlinkWriter.WriteMultiBuffer(data)
-			assert(err, IsNil)
+			common.Must(err)
 		}
 		}
 	}()
 	}()
 
 

+ 18 - 17
transport/internet/websocket/ws_test.go

@@ -7,6 +7,7 @@ import (
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/protocol/tls/cert"
 	"v2ray.com/core/common/protocol/tls/cert"
 	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/internet"
@@ -29,17 +30,17 @@ func Test_listenWSAndDial(t *testing.T) {
 
 
 			var b [1024]byte
 			var b [1024]byte
 			n, err := c.Read(b[:])
 			n, err := c.Read(b[:])
-			//assert(err, IsNil)
+			//common.Must(err)
 			if err != nil {
 			if err != nil {
 				return
 				return
 			}
 			}
 			assert(bytes.HasPrefix(b[:n], []byte("Test connection")), IsTrue)
 			assert(bytes.HasPrefix(b[:n], []byte("Test connection")), IsTrue)
 
 
 			_, err = c.Write([]byte("Response"))
 			_, err = c.Write([]byte("Response"))
-			assert(err, IsNil)
+			common.Must(err)
 		}(conn)
 		}(conn)
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	ctx := context.Background()
 	ctx := context.Background()
 	streamSettings := &internet.MemoryStreamConfig{
 	streamSettings := &internet.MemoryStreamConfig{
@@ -48,23 +49,23 @@ func Test_listenWSAndDial(t *testing.T) {
 	}
 	}
 	conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146), streamSettings)
 	conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146), streamSettings)
 
 
-	assert(err, IsNil)
+	common.Must(err)
 	_, err = conn.Write([]byte("Test connection 1"))
 	_, err = conn.Write([]byte("Test connection 1"))
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	var b [1024]byte
 	var b [1024]byte
 	n, err := conn.Read(b[:])
 	n, err := conn.Read(b[:])
-	assert(err, IsNil)
+	common.Must(err)
 	assert(string(b[:n]), Equals, "Response")
 	assert(string(b[:n]), Equals, "Response")
 
 
 	assert(conn.Close(), IsNil)
 	assert(conn.Close(), IsNil)
 	<-time.After(time.Second * 5)
 	<-time.After(time.Second * 5)
 	conn, err = Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146), streamSettings)
 	conn, err = Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146), streamSettings)
-	assert(err, IsNil)
+	common.Must(err)
 	_, err = conn.Write([]byte("Test connection 2"))
 	_, err = conn.Write([]byte("Test connection 2"))
-	assert(err, IsNil)
+	common.Must(err)
 	n, err = conn.Read(b[:])
 	n, err = conn.Read(b[:])
-	assert(err, IsNil)
+	common.Must(err)
 	assert(string(b[:n]), Equals, "Response")
 	assert(string(b[:n]), Equals, "Response")
 	assert(conn.Close(), IsNil)
 	assert(conn.Close(), IsNil)
 
 
@@ -86,30 +87,30 @@ func TestDialWithRemoteAddr(t *testing.T) {
 
 
 			var b [1024]byte
 			var b [1024]byte
 			n, err := c.Read(b[:])
 			n, err := c.Read(b[:])
-			//assert(err, IsNil)
+			//common.Must(err)
 			if err != nil {
 			if err != nil {
 				return
 				return
 			}
 			}
 			assert(bytes.HasPrefix(b[:n], []byte("Test connection")), IsTrue)
 			assert(bytes.HasPrefix(b[:n], []byte("Test connection")), IsTrue)
 
 
 			_, err = c.Write([]byte("Response"))
 			_, err = c.Write([]byte("Response"))
-			assert(err, IsNil)
+			common.Must(err)
 		}(conn)
 		}(conn)
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	conn, err := Dial(context.Background(), net.TCPDestination(net.DomainAddress("localhost"), 13148), &internet.MemoryStreamConfig{
 	conn, err := Dial(context.Background(), net.TCPDestination(net.DomainAddress("localhost"), 13148), &internet.MemoryStreamConfig{
 		ProtocolName:     "websocket",
 		ProtocolName:     "websocket",
 		ProtocolSettings: &Config{Path: "ws", Header: []*Header{{Key: "X-Forwarded-For", Value: "1.1.1.1"}}},
 		ProtocolSettings: &Config{Path: "ws", Header: []*Header{{Key: "X-Forwarded-For", Value: "1.1.1.1"}}},
 	})
 	})
 
 
-	assert(err, IsNil)
+	common.Must(err)
 	_, err = conn.Write([]byte("Test connection 1"))
 	_, err = conn.Write([]byte("Test connection 1"))
-	assert(err, IsNil)
+	common.Must(err)
 
 
 	var b [1024]byte
 	var b [1024]byte
 	n, err := conn.Read(b[:])
 	n, err := conn.Read(b[:])
-	assert(err, IsNil)
+	common.Must(err)
 	assert(string(b[:n]), Equals, "Response")
 	assert(string(b[:n]), Equals, "Response")
 
 
 	assert(listen.Close(), IsNil)
 	assert(listen.Close(), IsNil)
@@ -140,11 +141,11 @@ func Test_listenWSAndDial_TLS(t *testing.T) {
 			_ = conn.Close()
 			_ = conn.Close()
 		}()
 		}()
 	})
 	})
-	assert(err, IsNil)
+	common.Must(err)
 	defer listen.Close()
 	defer listen.Close()
 
 
 	conn, err := Dial(context.Background(), net.TCPDestination(net.DomainAddress("localhost"), 13143), streamSettings)
 	conn, err := Dial(context.Background(), net.TCPDestination(net.DomainAddress("localhost"), 13143), streamSettings)
-	assert(err, IsNil)
+	common.Must(err)
 	_ = conn.Close()
 	_ = conn.Close()
 
 
 	end := time.Now()
 	end := time.Now()