From c42ed62fd5e6b7c2e2ac48d20b1423f3d79843fd Mon Sep 17 00:00:00 2001 From: v2ray Date: Mon, 1 Aug 2016 22:59:18 +0200 Subject: [PATCH] remove use of small buffer in tests --- proxy/freedom/freedom_test.go | 4 ++-- proxy/shadowsocks/protocol_test.go | 24 ++++++++++++------------ proxy/socks/protocol/socks4_test.go | 2 +- proxy/socks/protocol/socks_test.go | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/proxy/freedom/freedom_test.go b/proxy/freedom/freedom_test.go index 0d0e5950d..4fcecbe25 100644 --- a/proxy/freedom/freedom_test.go +++ b/proxy/freedom/freedom_test.go @@ -52,7 +52,7 @@ func TestSinglePacket(t *testing.T) { traffic := ray.NewRay() data2Send := "Data to be sent to remote" - payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send)) + payload := alloc.NewLocalBuffer(2048).Clear().Append([]byte(data2Send)) go freedom.Dispatch(v2net.TCPDestination(v2net.LocalHostIP, port), payload, traffic) traffic.InboundInput().Close() @@ -78,7 +78,7 @@ func TestUnreachableDestination(t *testing.T) { }) traffic := ray.NewRay() data2Send := "Data to be sent to remote" - payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send)) + payload := alloc.NewLocalBuffer(2048).Clear().Append([]byte(data2Send)) err := freedom.Dispatch(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 128), payload, traffic) assert.Error(err).IsNotNil() diff --git a/proxy/shadowsocks/protocol_test.go b/proxy/shadowsocks/protocol_test.go index a9a686ded..803392b98 100644 --- a/proxy/shadowsocks/protocol_test.go +++ b/proxy/shadowsocks/protocol_test.go @@ -15,7 +15,7 @@ import ( func TestNormalRequestParsing(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80) request, err := ReadRequest(buffer, nil, false) @@ -28,7 +28,7 @@ func TestNormalRequestParsing(t *testing.T) { func TestEmptyPayload(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() _, err := ReadRequest(buffer, nil, false) assert.Error(err).Equals(io.EOF) } @@ -36,7 +36,7 @@ func TestEmptyPayload(t *testing.T) { func TestSingleBytePayload(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1) + buffer := alloc.NewLocalBuffer(2048).Clear().AppendBytes(1) _, err := ReadRequest(buffer, nil, false) assert.Error(err).Equals(transport.ErrCorruptedPacket) } @@ -44,7 +44,7 @@ func TestSingleBytePayload(t *testing.T) { func TestWrongAddressType(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear().AppendBytes(5) + buffer := alloc.NewLocalBuffer(2048).Clear().AppendBytes(5) _, err := ReadRequest(buffer, nil, false) assert.Error(err).Equals(transport.ErrCorruptedPacket) } @@ -52,15 +52,15 @@ func TestWrongAddressType(t *testing.T) { func TestInsufficientAddressRequest(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1) + buffer := alloc.NewLocalBuffer(2048).Clear().AppendBytes(1, 1) _, err := ReadRequest(buffer, nil, false) assert.Error(err).Equals(transport.ErrCorruptedPacket) - buffer = alloc.NewSmallBuffer().Clear().AppendBytes(4, 1) + buffer = alloc.NewLocalBuffer(2048).Clear().AppendBytes(4, 1) _, err = ReadRequest(buffer, nil, false) assert.Error(err).Equals(transport.ErrCorruptedPacket) - buffer = alloc.NewSmallBuffer().Clear().AppendBytes(3, 255, 1) + buffer = alloc.NewLocalBuffer(2048).Clear().AppendBytes(3, 255, 1) _, err = ReadRequest(buffer, nil, false) assert.Error(err).Equals(transport.ErrCorruptedPacket) } @@ -68,7 +68,7 @@ func TestInsufficientAddressRequest(t *testing.T) { func TestInsufficientPortRequest(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1, 2, 3, 4, 5) + buffer := alloc.NewLocalBuffer(2048).Clear().AppendBytes(1, 1, 2, 3, 4, 5) _, err := ReadRequest(buffer, nil, false) assert.Error(err).Equals(transport.ErrCorruptedPacket) } @@ -76,7 +76,7 @@ func TestInsufficientPortRequest(t *testing.T) { func TestOTARequest(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 0) auth := NewAuthenticator(HeaderKeyGenerator( @@ -91,7 +91,7 @@ func TestOTARequest(t *testing.T) { func TestInvalidOTARequest(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 1) auth := NewAuthenticator(HeaderKeyGenerator( @@ -104,7 +104,7 @@ func TestInvalidOTARequest(t *testing.T) { func TestUDPRequestParsing(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80, 1, 2, 3, 4, 5, 6) request, err := ReadRequest(buffer, nil, true) @@ -118,7 +118,7 @@ func TestUDPRequestParsing(t *testing.T) { func TestUDPRequestWithOTA(t *testing.T) { assert := assert.On(t) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() buffer.AppendBytes( 0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, diff --git a/proxy/socks/protocol/socks4_test.go b/proxy/socks/protocol/socks4_test.go index 88895bb84..b045bc514 100644 --- a/proxy/socks/protocol/socks4_test.go +++ b/proxy/socks/protocol/socks4_test.go @@ -31,7 +31,7 @@ func TestSocks4AuthenticationResponseToBytes(t *testing.T) { response := NewSocks4AuthenticationResponse(byte(0x10), 443, []byte{1, 2, 3, 4}) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() defer buffer.Release() response.Write(buffer) diff --git a/proxy/socks/protocol/socks_test.go b/proxy/socks/protocol/socks_test.go index db278f9fe..49d9a578f 100644 --- a/proxy/socks/protocol/socks_test.go +++ b/proxy/socks/protocol/socks_test.go @@ -84,7 +84,7 @@ func TestResponseWrite(t *testing.T) { [16]byte{}, v2net.Port(53), } - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() defer buffer.Release() response.Write(buffer) @@ -105,7 +105,7 @@ func TestSetIPv6(t *testing.T) { response := NewSocks5Response() response.SetIPv6([]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}) - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() defer buffer.Release() response.Write(buffer) assert.Bytes(buffer.Value).Equals([]byte{ @@ -118,7 +118,7 @@ func TestSetDomain(t *testing.T) { response := NewSocks5Response() response.SetDomain("v2ray.com") - buffer := alloc.NewSmallBuffer().Clear() + buffer := alloc.NewLocalBuffer(2048).Clear() defer buffer.Release() response.Write(buffer) assert.Bytes(buffer.Value).Equals([]byte{